Example #1
0
 /**
  * Clear datas with $uid key
  * @param mixed $uid
  * @return void
  */
 public function clear($uid = null)
 {
     $this->alloc();
     if ($uid) {
         return $this->session->offsetUnset($uid);
     }
     return $this->session->exchangeArray(array());
 }
 public function appendCollection(\Traversable $collection)
 {
     $buff = [];
     foreach ($this->collection as $i) {
         $buff[] = $i;
     }
     foreach ($collection as $i) {
         $buff[] = $i;
     }
     $this->collection->exchangeArray($buff);
 }
Example #3
0
 public function testArrayObjectUsage()
 {
     $data = array('prop' => 'value');
     $this->collection->exchangeArray(array((object) $data));
     $this->assertCount(1, $this->collection);
     $this->assertEquals((object) $data, $this->collection[0]);
     $this->collection[] = (object) $data;
     $this->assertCount(2, $this->collection);
     $this->assertEquals((object) $data, $this->collection[1]);
     foreach ($this->collection as $component) {
         $this->assertEquals((object) $data, $component);
     }
 }
 public function compile($name)
 {
     $source = $this->getLoader()->getSource($name);
     $cacheKey = $this->getCacheFilename($name);
     $phpStr = '';
     try {
         $this->partials->exchangeArray([new FileResource($this->getLoader()->getCacheKey($name))]);
         $phpStr = LightnCandy::compile($source, $this->options);
     } catch (\Exception $e) {
         throw new LoaderException($e->getMessage());
     }
     $this->cache->write($cacheKey, '<?php // ' . $name . PHP_EOL . $phpStr, $this->partials->getArrayCopy());
     return $phpStr;
 }
 /**
  * Do translation and workspace overlay
  *
  * @param \ArrayObject $data
  * @return void
  */
 public function languageAndWorkspaceOverlay(\ArrayObject $data)
 {
     $overlayedMetaData = $this->getTsfe()->sys_page->getRecordOverlay('sys_file_metadata', $data->getArrayCopy(), $this->getTsfe()->sys_language_content, $this->getTsfe()->sys_language_contentOL);
     if ($overlayedMetaData !== NULL) {
         $data->exchangeArray($overlayedMetaData);
     }
 }
Example #6
0
 /**
  * Loads settings
  * @param $force
  * @return unknown_type
  */
 function ld($force = false)
 {
     if ($this->loaded && !$force) {
         return;
     }
     global $DB;
     $where = array('`setset`.`property` = `settings`.`property`', 'settings.id' => $this->ID);
     if ($this->ID > 0) {
         global $Controller;
         $myself = $Controller->{(string) $this->ID}(OVERRIDE);
         if (is_a($myself, 'Group')) {
             $where['setset.visible'] = array(3, 4, 5, 6);
         } elseif (is_a($myself, 'User')) {
             $where['setset.visible'] = array(1, 2, 3, 4);
         } else {
             return false;
         }
     }
     $load = $DB->{'setset,settings'}->asArray($where, 'settings.property,settings.value,setset.type', false, true);
     if (!is_array($load)) {
         $load = array();
     }
     $this->_TYPE = array();
     $new_data = array();
     foreach ($load as $property => $data) {
         $new_data[$property] = $data['value'];
         $this->_TYPE[$property] = $data['type'];
     }
     parent::exchangeArray($new_data);
     $this->loaded = true;
 }
Example #7
0
 public function set($value)
 {
     if (!(is_array($value) || empty($value))) {
         throw new \InvalidArgumentException(sprintf('%s: Invalid data type. Expected `array` or `EMPTY`, was `%s`', get_class($this), gettype($value)), 1322148826);
     }
     if (is_null($this->modified)) {
         $this->lazyInitialization();
     }
     // handle set-NULL
     if ($value === NULL) {
         if ($this->data === NULL) {
             // nothing to do
         } else {
             $this->modified = TRUE;
             $this->data = NULL;
         }
         return;
     }
     // empty string translated to empty array
     if ($value === '') {
         $value = array();
     }
     if (is_null($this->data)) {
         $this->data = new \ArrayObject($value);
         $this->modified = TRUE;
     } elseif ($this->data->getArrayCopy() !== $value) {
         $this->data->exchangeArray($value);
         $this->modified = TRUE;
     }
 }
 public function exchangeArray($Array)
 {
     foreach ($Array as $Value) {
         $this->VerifyValue($Value);
     }
     parent::exchangeArray($Array);
 }
Example #9
0
 public function exchangeArray($Input)
 {
     $this->IsAltered = true;
     $this->RemovedEntities = array_merge($this->RemovedEntities, $this->getArrayCopy());
     $this->AddedEntities = array_merge($this->AddedEntities, $Input);
     parent::exchangeArray($Input);
 }
Example #10
0
 /** {@inheritdoc} */
 public function exchangeArray($input)
 {
     if (isset($input['Id'])) {
         // Add Timestamp property
         $input['Timestamp'] = new \DateTime("@{$input['Id']}");
     }
     return parent::exchangeArray($input);
 }
 /**
  * @param mixed $input
  * @return array the old array
  */
 public function exchangeArray($input)
 {
     foreach ($input as $value) {
         if (!is_a($value, $this->allowedClass)) {
             $this->throwInvalid($value);
         }
     }
     return parent::exchangeArray($input);
 }
Example #12
0
 /**
  * @param mixed $data
  * @return void
  */
 public function exchangeArray($data)
 {
     parent::exchangeArray($data);
     if ($data && is_array($data)) {
         foreach ($data as $key => $value) {
             $this->{$key} = $value;
         }
     }
 }
Example #13
0
 /**
  * @param Image[] $input
  * @throws \InvalidArgumentException
  * @return Image[]|void
  */
 public function exchangeArray($input)
 {
     foreach ($input as $idx => $value) {
         if (false === $value instanceof Image) {
             throw new \InvalidArgumentException("Value[{$idx}] is not an instance of Image");
         }
         $value->setCollection($this);
     }
     return parent::exchangeArray($input);
 }
 public function setSession(\Nethgui\Utility\SessionInterface $session)
 {
     /* @var $data \ArrayObject */
     $data = $session->retrieve(__CLASS__);
     if ($data !== NULL) {
         /* @var $data \ArrayObject */
         $this->data->exchangeArray(array_replace_recursive($data->getArrayCopy(), $this->data->getArrayCopy()));
     }
     $session->store(__CLASS__, $this->data);
     return $this;
 }
 /**
  * See SPL class ArrayObject.
  * Performs additional value checks on the array.
  * 
  * @param array(ezcPersistentRelation) $array New relations array.
  * @return void
  */
 public function exchangeArray($array)
 {
     foreach ($array as $offset => $value) {
         if (!$value instanceof ezcPersistentRelation && !$value instanceof ezcPersistentRelationCollection) {
             throw new ezcBaseValueException('value', $value, 'ezcPersistentRelation or ezcPersistentRelationCollection');
         }
         if (!is_string($offset) || strlen($offset) < 1) {
             throw new ezcBaseValueException('offset', $offset, 'string, length > 0');
         }
     }
     parent::exchangeArray($array);
 }
Example #16
0
 /**
  * Loads key values data from a string or file
  * 
  * @param string $string String or file to load
  */
 public function load($string)
 {
     if (is_readable($string)) {
         $string = file_get_contents($string);
     }
     // Use token_get_all() to easily ignore comments and whitespace
     $tokens = token_get_all("<?php\n" . $string . "\n?>");
     $data = $this->_parse($tokens);
     // Strip root section
     $data = reset($data);
     parent::exchangeArray($data);
 }
 /**
  * See SPL class ArrayObject.
  * Performs additional value checks on the array.
  * 
  * @param array(ezcPersistentObjectProperty) $array New properties array.
  * @return void
  */
 public function exchangeArray($array)
 {
     foreach ($array as $offset => $value) {
         if ($value instanceof ezcPersistentObjectProperty === false) {
             throw new ezcBaseValueException('value', $value, 'ezcPersistentObjectProperty');
         }
         if (!is_string($offset) || strlen($offset) < 1) {
             throw new ezcBaseValueException('offset', $offset, 'string, length > 0');
         }
     }
     parent::exchangeArray($array);
 }
Example #18
0
 /**
  * Protected exchangeArray().
  * @param  array  new array
  * @return Collection  provides a fluent interface
  */
 protected function setArray($array)
 {
     parent::exchangeArray($array);
     return $this;
 }
Example #19
0
 /**
  * @covers ::validateChunk
  */
 public function testFile_validateChunk()
 {
     // No $_FILES
     $request = new Request($this->requestArr);
     $file = new File($this->config, $request);
     $this->assertFalse($file->validateChunk());
     // No 'file' key $_FILES
     $fileInfo = new \ArrayObject();
     $request = new Request($this->requestArr, $fileInfo);
     $file = new File($this->config, $request);
     $this->assertFalse($file->validateChunk());
     // Upload OK
     $fileInfo->exchangeArray(['size' => 10, 'error' => UPLOAD_ERR_OK, 'tmp_name' => '']);
     $this->assertTrue($file->validateChunk());
     // Chunk size doesn't match
     $fileInfo->exchangeArray(['size' => 9, 'error' => UPLOAD_ERR_OK, 'tmp_name' => '']);
     $this->assertFalse($file->validateChunk());
     // Upload error
     $fileInfo->exchangeArray(['size' => 10, 'error' => UPLOAD_ERR_EXTENSION, 'tmp_name' => '']);
     $this->assertFalse($file->validateChunk());
 }
Example #20
0
<?php

// Array of available fruits
$fruits = array("lemons" => 1, "oranges" => 4, "bananas" => 5, "apples" => 10);
// Array of locations in Europe
$locations = array('Amsterdam', 'Paris', 'London');
$fruitsArrayObject = new ArrayObject($fruits);
// Now exchange fruits for locations
$old = $fruitsArrayObject->exchangeArray($locations);
print_r($old);
print_r($fruitsArrayObject);
 /**
  * Set the namespaces property to an \ArrayObject instance
  *
  * @param array|\ArrayObject $namespaces
  */
 protected function setNamespaces($namespaces)
 {
     if ($this->namespaces instanceof \ArrayObject) {
         $this->namespaces->exchangeArray($namespaces);
     } else {
         $this->namespaces = new \ArrayObject($namespaces);
     }
 }
Example #22
0
 /**
  * Overloads the `ArrayObject::exchangeArray()` method to ensure that
  * all keys are changed to lowercase.
  *
  * @param   mixed   $input
  * @return  array
  * @since   3.2.0
  */
 public function exchangeArray($input)
 {
     /**
      * @link http://www.w3.org/Protocols/rfc2616/rfc2616.html
      *
      * HTTP header declarations should be treated as case-insensitive
      */
     $input = array_change_key_case((array) $input, CASE_LOWER);
     return parent::exchangeArray($input);
 }
Example #23
0
 /**
  * Overloads the `ArrayObject::exchangeArray()` method to ensure all
  * values passed are parsed correctly into a [Kohana_Http_Header_Value].
  *
  *     // Input new headers
  *     $headers->exchangeArray(array(
  *          'date'          => 'Wed, 24 Nov 2010 21:09:23 GMT',
  *          'cache-control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
  *     ));
  *
  * @param   array    $array Array to exchange
  * @return  array
  */
 public function exchangeArray($array)
 {
     return parent::exchangeArray(Http_Header::parse_header_values($array));
 }
Example #24
0
 /**
  * Scans and parses PHP files.
  *
  * @return array
  * @throws \RuntimeException If no PHP files have been found.
  */
 public function parse()
 {
     $files = array();
     $flags = \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | \RecursiveDirectoryIterator::SKIP_DOTS;
     if (defined('\\RecursiveDirectoryIterator::FOLLOW_SYMLINKS')) {
         // Available from PHP 5.3.1
         $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
     }
     foreach ($this->config->source as $source) {
         $entries = array();
         if (is_dir($source)) {
             foreach (new \RecursiveIteratorIterator(new SourceFilesFilterIterator(new \RecursiveDirectoryIterator($source, $flags), $this->config->exclude)) as $entry) {
                 if (!$entry->isFile()) {
                     continue;
                 }
                 $entries[] = $entry;
             }
         } elseif ($this->isPhar($source)) {
             if (!extension_loaded('phar')) {
                 throw new RuntimeException('Phar extension is not loaded');
             }
             foreach (new \RecursiveIteratorIterator(new \Phar($source, $flags)) as $entry) {
                 if (!$entry->isFile()) {
                     continue;
                 }
                 $entries[] = $entry;
             }
         } else {
             $entries[] = new \SplFileInfo($source);
         }
         $regexp = '~\\.' . implode('|', $this->config->extensions->toArray()) . '$~i';
         foreach ($entries as $entry) {
             if (!preg_match($regexp, $entry->getFilename())) {
                 continue;
             }
             $pathName = $this->normalizePath($entry->getPathName());
             $files[$pathName] = $entry->getSize();
             if (false !== $entry->getRealPath() && $pathName !== $entry->getRealPath()) {
                 $this->symlinks[$entry->getRealPath()] = $pathName;
             }
         }
     }
     if (empty($files)) {
         throw new RuntimeException('No PHP files found');
     }
     $this->fireEvent('parseStart', array_sum($files));
     $broker = new Broker(new Backend($this, !empty($this->config->report)), Broker::OPTION_DEFAULT & ~(Broker::OPTION_PARSE_FUNCTION_BODY | Broker::OPTION_SAVE_TOKEN_STREAM));
     $errors = array();
     foreach ($files as $filePath => $size) {
         $content = $this->charsetConvertor->convertFile($filePath);
         try {
             $broker->processString($content, $filePath);
         } catch (\Exception $e) {
             $errors[] = $e;
         }
         $this->fireEvent('parseProgress', $size);
     }
     // Classes
     $this->parsedClasses->exchangeArray($broker->getClasses(Backend::TOKENIZED_CLASSES | Backend::INTERNAL_CLASSES | Backend::NONEXISTENT_CLASSES));
     $this->parsedClasses->uksort('strcasecmp');
     // Constants
     $this->parsedConstants->exchangeArray($broker->getConstants());
     $this->parsedConstants->uksort('strcasecmp');
     // Functions
     $this->parsedFunctions->exchangeArray($broker->getFunctions());
     $this->parsedFunctions->uksort('strcasecmp');
     $documentedCounter = function ($count, $element) {
         return $count += (int) $element->isDocumented();
     };
     return (object) array('classes' => count($broker->getClasses(Backend::TOKENIZED_CLASSES)), 'constants' => count($this->parsedConstants), 'functions' => count($this->parsedFunctions), 'internalClasses' => count($broker->getClasses(Backend::INTERNAL_CLASSES)), 'documentedClasses' => array_reduce($broker->getClasses(Backend::TOKENIZED_CLASSES), $documentedCounter), 'documentedConstants' => array_reduce($this->parsedConstants->getArrayCopy(), $documentedCounter), 'documentedFunctions' => array_reduce($this->parsedFunctions->getArrayCopy(), $documentedCounter), 'documentedInternalClasses' => array_reduce($broker->getClasses(Backend::INTERNAL_CLASSES), $documentedCounter), 'errors' => $errors);
 }
 /**
  * Init constant list by defined and magic constants
  */
 public function initEnvironmentConstants()
 {
     $constants = ['__DIR__', '__FILE__', '__LINE__', '__CLASS__', '__TRAIT__', '__METHOD__', '__FUNCTION__', '__NAMESPACE__', '::'];
     $constants = array_merge($constants, array_keys(get_defined_constants()), $this->constants->getArrayCopy());
     $this->constants->exchangeArray($constants);
 }
 public function prepareDays()
 {
     $JourFactory = new FlyweightJourFactory();
     $arrayTemp = $this->AffectationDone->getArrayCopy();
     /**		for ($i = count($arrayTemp)-2; $i >=0; $i--) {
     			for ($j = 0; $j <= $i; $j++) {
     				if($arrayTemp[$j+1]->Heure->getHoraireDebut() > $arrayTemp[$j]->Heure->getHoraireDebut()){
     					$t = $arrayTemp[$j+1];
     					$arrayTemp[$j+1] = $arrayTemp[$j];
     					$arrayTemp[$j] = $t;
     				}
     			}
     		}
     **/
     $array08 = new ArrayObject(array());
     $array10 = new ArrayObject(array());
     $array14 = new ArrayObject(array());
     $array16 = new ArrayObject(array());
     for ($i = 0; $i < count($arrayTemp); $i++) {
         if ($arrayTemp[$i]->Heure->getHoraireDebut() == "16H30") {
             $array16->append($arrayTemp[$i]);
         }
         if ($arrayTemp[$i]->Heure->getHoraireDebut() == "14H30") {
             $array14->append($arrayTemp[$i]);
         }
         if ($arrayTemp[$i]->Heure->getHoraireDebut() == "10H00") {
             $array10->append($arrayTemp[$i]);
         }
         if ($arrayTemp[$i]->Heure->getHoraireDebut() == "08H00") {
             $array08->append($arrayTemp[$i]);
         }
     }
     //		var_dump(count($array08));
     //		var_dump(count($array10));
     //		var_dump(count($array14));
     //		var_dump(count($array16));
     $allarray = array($array08, $array10, $array14, $array16);
     $max = 0;
     for ($i = 1; $i < count($allarray); $i++) {
         if (count($allarray[$max]) < count($allarray[$i])) {
             $max = $i;
         }
     }
     //echo "le max est : ".count($allarray[$max])." et indice : ".$max;
     $arraymax = $allarray[$max];
     for ($i = 0; $i < count($arraymax); $i++) {
         for ($y = 1; $y <= 6; $y++) {
             $makefunction = "makeJour" . $y;
             $jourLibelle = $JourFactory->{$makefunction}();
             //var_dump($jourLibelle);
             if ($jourLibelle == "Mercredi" || $jourLibelle == "Samedi") {
                 $length08 = $array08->count();
                 $key08 = rand(0, $length08);
                 //$key08 = 0;
                 $length10 = $array10->count();
                 $key10 = rand(0, $length10);
                 $aff08 = null;
                 $aff10 = null;
                 if ($array08->offsetExists($key08) == true) {
                     $aff08 = $array08[$key08];
                     $array08->offsetUnset($key08);
                     $array08->exchangeArray($array08->getArrayCopy());
                     //						echo "08H00 : ".$key08.",",PHP_EOL;
                 }
                 if ($array10->offsetExists($key10) == true) {
                     $aff10 = $array10[$key10];
                     $array10->offsetUnset($key10);
                     //						echo "10H00 : ".$key10.",",PHP_EOL;
                 }
                 if (!is_null($aff08) || !is_null($aff10)) {
                     array_push($this->JoursList, new Jour($jourLibelle, array($aff08, $aff10)));
                 }
                 //$array08->offsetUnset($key08);
             } else {
                 $length08 = $array08->count();
                 $key08 = rand(0, $length08);
                 //$key08 = 0;
                 $length10 = $array10->count();
                 $key10 = rand(0, $length10);
                 $length14 = $array14->count();
                 $key14 = rand(0, $length14);
                 $length16 = $array16->count();
                 $key16 = rand(0, $length16);
                 $aff08 = null;
                 $aff10 = null;
                 $aff14 = null;
                 $aff16 = null;
                 if ($array08->offsetExists($key08) == true) {
                     $aff08 = $array08[$key08];
                     $array08->offsetUnset($key08);
                     //$array08->exchangeArray($array08->getArrayCopy());
                     //						echo "08H00 : ".$key08.",",PHP_EOL;
                 }
                 if ($array10->offsetExists($key10) == true) {
                     $aff10 = $array10[$key10];
                     $array10->offsetUnset($key10);
                     //						echo "10H00 : ".$key10.",",PHP_EOL;
                 }
                 if ($array14->offsetExists($key14) == true) {
                     $aff14 = $array14[$key14];
                     $array14->offsetUnset($key14);
                     //$array14->exchangeArray($array08->getArrayCopy());
                     //						echo "14H30 : ".$key14.",",PHP_EOL;
                 }
                 if ($array16->offsetExists($key16) == true) {
                     $aff16 = $array16[$key16];
                     $array16->offsetUnset($key16);
                     //$array14->exchangeArray($array08->getArrayCopy());
                     //						echo "16H30 : ".$key16.",",PHP_EOL;
                 }
                 //					echo "</br>";
                 //					var_dump($aff08);
                 //					var_dump($aff10);
                 //					var_dump($aff14);
                 //					var_dump($aff16);
                 if (!is_null($aff08) || !is_null($aff10) || !is_null($aff14) || !is_null($aff16)) {
                     array_push($this->JoursList, new Jour($jourLibelle, array($aff08, $aff10, $aff14, $aff16)));
                 }
                 //
             }
         }
         //			echo "</br>";
     }
     //		echo "</br>";
     //			var_dump(count($array08));
     //			var_dump(count($array10));
     //			var_dump(count($array14));
     //			var_dump(count($array16));
     //			$this->AffectationRemaining->exchangeArray(array($array08,$array10,$array14,$array16));
     //			echo "</br>";
     //var_dump(count($this->JoursList));
     //var_dump($this->JoursList[5]->Affectations);
     //var_dump($this->JoursList[5]->LibelleJour);
     //var_dump(($array08));
     //var_dump(count($array08));
     //var_dump(count($array10));
     //var_dump(count($array14));
     //var_dump(count($array16));
     //echo "</br>";
     $this->distributeHours($array08, $array10, $array14, $array16);
     //var_dump(count($array08));
     //var_dump(count($array10));
     //var_dump(count($array14));
     //var_dump(count($array16));
     //echo "</br>";
     $this->distributeHours($array08, $array10, $array14, $array16);
     //var_dump(count($array08));
     //var_dump(count($array10));
     //var_dump(count($array14));
     //var_dump(count($array16));
     //echo "</br>";
     $this->distributeHours($array08, $array10, $array14, $array16);
     //var_dump(count($array08));
     //var_dump(count($array10));
     //var_dump(count($array14));
     //var_dump(count($array16));
     // don't worry I will found a recursive formula !!!
     //var_dump(count($this->JoursList));
     //var_dump(count(array_chunk($this->JoursList, 6)));
     //var_dump($this->JoursList[4]);
     // and the end we fill the SemaineList or the list of weeks. Oh Yeah !!!
     //$this->SemaineList = array_chunk($this->JoursList, 6);
     //var_dump($this->SemaineList[3]);
 }
Example #27
0
 /**
  * Truncates the session by removing all
  * stored values.
  *
  * @return void
  */
 public function truncate()
 {
     $this->values->exchangeArray([]);
 }
Example #28
0
 /**
  *
  * Set array IDs of messages to delete.
  *
  * This id was returned after sending message.
  *
  * @param $ids
  * @return $this
  * @throws \TMSolution\SmsBundle\Api\SMSApi\Exception\ActionException
  */
 public function filterByIds(array $ids)
 {
     $this->id->exchangeArray($ids);
     return $this;
 }
Example #29
0
 /**
  * @param mixed $data
  *
  * @return $this
  */
 public function exchangeArray($data)
 {
     if ($data instanceof ArrayObject) {
         $data = $data->getArrayCopy();
     }
     if ($data instanceof \Iterator) {
         $data = iterator_to_array($data);
     }
     if (!is_array($data)) {
         $data = [$data];
     }
     parent::exchangeArray($data);
     return $this;
 }
Example #30
0
 /**
  * Protected exchangeArray().
  * @param  array  new array
  * @return void
  */
 protected function setArray($array)
 {
     parent::exchangeArray($array);
 }