Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/vendors/Netcarver/Textile/DataBag.php - 98 lines - 2909 bytes - Summary - Text - Print

Description: Textile - A Humane Web Text Generator.

   1  <?php
   2  
   3  /**
   4   * Textile - A Humane Web Text Generator.
   5   *
   6   * @link https://github.com/textile/php-textile
   7   */
   8  
   9  /*
  10   * Copyright (c) 2016-2017, Netcarver https://github.com/netcarver
  11   *
  12   * Redistribution and use in source and binary forms, with or without
  13   * modification, are permitted provided that the following conditions are met:
  14   *
  15   * * Redistributions of source code must retain the above copyright notice,
  16   * this list of conditions and the following disclaimer.
  17   *
  18   * * Redistributions in binary form must reproduce the above copyright notice,
  19   * this list of conditions and the following disclaimer in the documentation
  20   * and/or other materials provided with the distribution.
  21   *
  22   * * Neither the name Textile nor the names of its contributors may be used to
  23   * endorse or promote products derived from this software without specific
  24   * prior written permission.
  25   *
  26   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36   * POSSIBILITY OF SUCH DAMAGE.
  37   */
  38  
  39  namespace Netcarver\Textile;
  40  
  41  /**
  42   * Simple data storage.
  43   *
  44   * This class allows storing assignments in an internal
  45   * data array.
  46   *
  47   * bc. use Netcarver\Textile\DataBag;
  48   * $plant = new DataBag(array('key' => 'value'));
  49   * $plant->flower('rose')->color('red');
  50   *
  51   * @internal
  52   */
  53  
  54  class DataBag
  55  {
  56      /**
  57       * The data array stored in the bag.
  58       *
  59       * @var array
  60       */
  61  
  62      protected $data;
  63  
  64      /**
  65       * Constructor.
  66       *
  67       * @param array|null $data The initial data array stored in the bag
  68       */
  69  
  70      public function __construct(array $data = null)
  71      {
  72          $this->data = (array) $data;
  73      }
  74  
  75      /**
  76       * Adds a value to the bag.
  77       *
  78       * Empty values are rejected, unless the
  79       * second argument is set TRUE.
  80       *
  81       * bc. use Netcarver\Textile\DataBag;
  82       * $plant = new DataBag(array('key' => 'value'));
  83       * $plant->flower('rose')->color('red')->emptyValue(false, true);
  84       *
  85       * @param   string $name   The name
  86       * @param   array  $params Arguments
  87       * @return  DataBag
  88       */
  89  
  90      public function __call($name, array $params)
  91      {
  92          if (!empty($params[1]) || !empty($params[0])) {
  93              $this->data[$name] = $params[0];
  94          }
  95  
  96          return $this;
  97      }
  98  }

title

Description

title

Description

title

Description

title

title

Body