Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/vendors/Netcarver/Textile/DataBag.php - 100 lines - 2933 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  namespace Netcarver\Textile;
  10  
  11  /*
  12   * Copyright (c) 2013, Netcarver https://github.com/netcarver
  13   *
  14   * Redistribution and use in source and binary forms, with or without
  15   * modification, are permitted provided that the following conditions are met:
  16   *
  17   * * Redistributions of source code must retain the above copyright notice,
  18   * this list of conditions and the following disclaimer.
  19   *
  20   * * Redistributions in binary form must reproduce the above copyright notice,
  21   * this list of conditions and the following disclaimer in the documentation
  22   * and/or other materials provided with the distribution.
  23   *
  24   * * Neither the name Textile nor the names of its contributors may be used to
  25   * endorse or promote products derived from this software without specific
  26   * prior written permission.
  27   *
  28   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  29   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  32   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  34   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  35   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  37   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38   * POSSIBILITY OF SUCH DAMAGE.
  39   */
  40  
  41  /**
  42   * Simple data storage.
  43   *
  44   * This class to allows storing assignments in an internal
  45   * data array.
  46   *
  47   * <code>
  48   * use Netcarver\Textile\DataBag;
  49   * $plant = new DataBag(array('key' => 'value'));
  50   * $plant->flower('rose')->color('red');
  51   * </code>
  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       * <code>
  82       * use Netcarver\Textile\DataBag;
  83       * $plant = new DataBag(array('key' => 'value'));
  84       * $plant->flower('rose')->color('red')->emptyValue(false, true);
  85       * </code>
  86       *
  87       * @param   string $name   The name
  88       * @param   array  $params Arguments
  89       * @return  DataBag
  90       */
  91  
  92      public function __call($name, array $params)
  93      {
  94          if (!empty($params[1]) || !empty($params[0])) {
  95              $this->data[$name] = $params[0];
  96          }
  97  
  98          return $this;
  99      }
 100  }

title

Description

title

Description

title

Description

title

title

Body