/** * Class construct * @param array|\ArrayObject|null $array * @return void */ public function __construct($array = null, array $options = null) { $options = array_merge(null === $options ? array() : $options, array('type' => 'callable', 'indexType' => static::INDEX_NUMERIC, 'readonly' => false)); if (array_key_exists('name', $options)) { $this->setName($options['name']); } parent::__construct($array, $options); }
/** * Overrides the default behavior of offsetSet so that when setting an entry * the type and index type are checked * @param string|int $index * @param mixed $value * @return void */ public function offsetSet($index, $value) { if (is_string($value) && null !== ($value = \Nimbles\Http\Header::factory($index, $value, true))) { $index = $value->getName(); } if (null === $value) { return; } parent::offsetSet($index, $value); }
/** * Overloads offsetSet to restrict value type * @param int|string $key * @param \Nimbles\Http\Cookie $value * @return void * @throws \Nimbles\Http\Cookie\Exception\InvalidInstance */ public function offsetSet($key, $value) { if (is_string($value)) { $value = new Cookie(array('name' => $key, 'value' => $value)); } if (!$value instanceof Cookie) { throw new Cookie\Exception\InvalidInstance('Invalid value, must be an instance of Nimbles\\Http\\Cookie'); } if (null === $value->getName()) { $value->setName($key); } return parent::offsetSet($value->getName(), $value); }
/** * Gets a file * @param string|null $key * @return array|null */ public function getFile($key = null) { if (null === $this->_files) { $this->_files = new Collection($this->getFilesRaw(), array('type' => 'string', 'indexType' => Collection::INDEX_ASSOCIATIVE, 'readonly' => true)); $this->_files->setFlags(Collection::ARRAY_AS_PROPS); } if (null === $key) { return $this->_files; } return $this->_files->offsetExists($key) ? $this->_files[$key] : null; }
/** * Class construct * * @param array|\ArrayObject $array * @param array $options */ public function __construct($array = null, array $options = null) { $options = array_merge(null === $options ? array('readonly' => false) : $options, array('indexType' => static::INDEX_MIXED)); parent::__construct($array, $options); $this->setFlags(static::ARRAY_AS_PROPS); }
/** * Class construct * @param array|\ArrayObject|null $array * @return void */ public function __construct($array = null, array $options = null) { $options = array_merge(null === $options ? array() : $options, array('type' => 'Nimbles\\Core\\Event', 'indexType' => static::INDEX_ASSOCIATIVE, 'readonly' => false)); parent::__construct($array, $options); $this->setFlags(self::ARRAY_AS_PROPS); }
/** * Tests creating a collection with options * @param mixed $options * @return void * * @dataProvider optionsProvider */ public function testConstructOptions($options) { $collection = new Collection(null, $options); $this->assertEquals(null, $collection->getType()); $this->assertEquals(Collection::INDEX_MIXED, $collection->getIndexType()); $this->assertFalse($collection->isReadOnly()); }