public function serialize() { foreach (new \ArrayIterator($this) as $index => $object) { if ($object instanceof DisposableInterface && $object->isDisposed()) { $this->offsetUnset($index); } } return parent::serialize(); }
public function getComponentData() { $cachedData = new \ArrayObject(['test_component1' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['argument_name1' => ['value' => 'value1']], ManagerInterface::CHILDREN_KEY => ['custom' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['custom_name1' => ['value' => 'custom_value1']], ManagerInterface::CHILDREN_KEY => []]]]]); return [['test_component1', new \ArrayObject(), $cachedData->serialize(), [], ['test_component1' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['argument_name1' => ['argument' => 'value1']], ManagerInterface::CHILDREN_KEY => ['custom' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['custom_name1' => ['argument' => 'custom_value1']], ManagerInterface::CHILDREN_KEY => []]]]]], ['test_component2', new \ArrayObject(['test_component2' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['argument_name2' => ['value' => 'value2']], ManagerInterface::CHILDREN_KEY => ['test_component21' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['argument_name21' => ['value' => 'value21']], ManagerInterface::CHILDREN_KEY => []]]]]), false, ['componentGroup' => [0 => [Converter::DATA_ARGUMENTS_KEY => ['argument_name2' => ['value' => 'value2']], Converter::DATA_ATTRIBUTES_KEY => ['name' => 'attribute_name2'], 'test_component21' => [0 => [Converter::DATA_ARGUMENTS_KEY => ['argument_name21' => ['value' => 'value21']], Converter::DATA_ATTRIBUTES_KEY => ['name' => 'attribute_name21']]]]]], ['test_component2' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['argument_name2' => ['argument' => 'value2']], ManagerInterface::COMPONENT_ATTRIBUTES_KEY => ['name' => 'attribute_name2'], ManagerInterface::CHILDREN_KEY => ['attribute_name21' => [ManagerInterface::COMPONENT_ARGUMENTS_KEY => ['argument_name21' => ['argument' => 'value21']], ManagerInterface::COMPONENT_ATTRIBUTES_KEY => ['name' => 'attribute_name21'], ManagerInterface::CHILDREN_KEY => []]]]]]]; }
/** * overwrites the ArrayObject serialize function so that: * - $container->serialize() will serialize only the data collection but not the object instance * - serialize($container) will serialize the whole container instance * * @error 16308 * @return string */ public function serialize() { $debug = debug_backtrace(); if (is_array($debug) && array_key_exists('line', $debug[0])) { return serialize($this->getArrayCopy()); } else { $this->rewind(); return parent::serialize(); } }
public function serialize() { return parent::serialize(); }
/** * Hack to unset logger instance which cannot be serialized * * @return string */ public function serialize() { $logger = $this->_logger; unset($this->_logger); $result = parent::serialize(); $this->_logger = $logger; return $result; }
/** * Serializes key values data and root section name */ public function serialize() { return serialize(array('data' => parent::serialize(), 'name' => $this->_name)); }
/** * Serialization * { @internal Don't serialze the connection }} * * @return array */ public function serialize() { if (isset($this->_connection)) { $clone = clone $this; unset($clone->_connection); return $clone->serialize(); } return parent::serialize(); }
/** * Serialize an ArrayObject * @return void The serialized representation of the <b>ArrayObject</b>. */ public function serialize() { if (version_compare(PHP_VERSION, '5.3.0', '>=')) { return parent::serialize(); } $serialized = serialize($this->getArrayCopy()); $serialized = 'x:i:0;' . $serialized . ';m:a:0:{}'; return $serialized; }
/** * @covers ::serialize * @covers ::unserialize * @dataProvider basicDataProvider() */ public function testTraitImpartsSerializableInterface(\ArrayObject $seedArray) { $serialString = $seedArray->serialize(); $mock = $this->getArrayObjectDecorator($seedArray); $this->assertEquals($serialString, $mock->serialize()); $mock2 = $this->getArrayObjectDecorator(new \ArrayObject()); $mock2->unserialize($serialString); $this->assertEquals($serialString, $mock2->serialize()); }
/** * Calculates an hash value for all files with certain extensions. * This is used to test if the hash value changed, so if * it changed, the appserver can react accordingly. * * @param \SplFileInfo $directory The directory to watch * * @return string The hash value build out of the found filenames */ protected function getDirectoryHash(\SplFileInfo $directory) { // prepare the array $files = new \ArrayObject(); // prepare the array with the file extensions of the files used to build the hash $extensionsToWatch = $this->getExtensionsToWatch(); // clear the cache clearstatcache(); // add all files with the found extensions to the array foreach (glob($directory . '/*.{' . implode(',', $extensionsToWatch) . '}', GLOB_BRACE) as $filename) { $files->append($filename); } // calculate and return the hash value for the array return md5($files->serialize()); }
<?php $dados = ['salmão', 'tilápia', 'sardinha', 'badejo', 'pescada', 'dourado', 'corvina', 'cavala', 'bagre']; $objarray = new ArrayObject($dados); $objarray->append('bacalhau'); print 'Posição 2: ' . $objarray->offsetGet(2) . '<br>' . PHP_EOL; $objarray->offsetSet(2, 'linguado'); print 'Posição 2: ' . $objarray->offsetGet(2) . '<br>' . PHP_EOL; $objarray->offsetUnset(4); if ($objarray->offsetExists(10)) { echo 'Posição 10 encontrada' . '<br>' . PHP_EOL; } else { echo 'Posição 10 não encontrada' . '<br>' . PHP_EOL; } print 'Total: ' . $objarray->count(); $objarray[] = 'atum'; $objarray->natsort(); print '<br>' . PHP_EOL; foreach ($objarray as $item) { print 'Item: ' . $item . '<br>' . PHP_EOL; } print $objarray->serialize();
/** * Calculates an hash value for all files with certain extensions. * This is used to test if the hash value changed, so if * it changed, the appserver can react accordingly. * * @param \SplFileInfo $directory The directory to watch * @param array $extensionsToWatch The extensions we have to look for * * @return string The hash value build out of the found filenames */ protected function getDirectoryHash(\SplFileInfo $directory, array $extensionsToWatch) { // prepare the array $files = new \ArrayObject(); // add all files with the found extensions to the array foreach (new \DirectoryIterator($directory) as $fileInfo) { if ($fileInfo->isFile() && in_array($fileInfo->getExtension(), $extensionsToWatch)) { $files->append($fileInfo->getFilename()); } } // calculate and return the hash value for the array return md5($files->serialize()); }
<?php $a = new ArrayObject(array(1, 2, 3)); $b = $a->serialize(); $c = new ArrayObject(); $d = $c->unserialize($b); var_dump($a); var_dump($c); var_dump($d); var_dump($a == $c);
/** * Implementation of ArrayAccess::serialize() * * Returns a serialized ArrayObject. * * @return string The serialized representation of the ArrayObject. */ public function serialize() { return $this->arrayObject->serialize(); }