Example #1
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = ArrayHelper::merge(parent::behaviors(), ['authenticator' => ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()], 'corsFilter' => ['class' => \backend\rest\filters\Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['POST', 'PUT', 'OPTIONS', 'PATCH', 'DELETE'], 'Access-Control-Request-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Max-Age' => 3600, 'Access-Control-Expose-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link']]]]);
     if (isset(\Yii::$app->params['httpCacheActive']) and \Yii::$app->params['httpCacheActive']) {
         $params = \Yii::$app->getRequest()->getQueryParams();
         unset($params['accessToken']);
         $behaviors['httpCache'] = ['class' => HttpCache::className(), 'params' => $params, 'lastModified' => function ($action, $params) {
             $q = new \yii\db\Query();
             $class = $this->modelClass;
             if (in_array('updated_at', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('updated_at'));
             }
             if (in_array('modified', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('modified'));
             }
             return null;
         }, 'etagSeed' => function (Action $action, $params) {
             $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($params));
             $keys = array();
             foreach ($iterator as $key => $value) {
                 // Build long key name based on parent keys
                 for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
                     $key = $iterator->getSubIterator($i)->key() . '_' . $key;
                     if (!is_array($iterator->getSubIterator($i)->current())) {
                         $value = $iterator->getSubIterator($i)->current() . '_' . $value;
                     }
                 }
                 $keys[] = $key . '-' . $value;
             }
             $uniqueId = implode('-', $keys);
             return $uniqueId;
         }];
     }
     return $behaviors;
 }
 private function _convertToDotNotation()
 {
     foreach ($this->_iterator as $leafValue) {
         $keys = [];
         foreach (range(0, $this->_iterator->getDepth()) as $depth) {
             $keys[] = $this->_iterator->getSubIterator($depth)->key();
         }
         $key = join(self::DELIMITER, $keys);
         $this->_result[$key] = $leafValue;
     }
 }
Example #3
0
 protected function parseCfg()
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data));
     $cfg = array();
     foreach ($iterator as $key => $value) {
         for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
             $key = $iterator->getSubIterator($i)->key() . '.' . $key;
         }
         $cfg[$key] = $value;
     }
     foreach ($cfg as $key => $value) {
         if (is_string($value)) {
             if ($count = preg_match_all('({{(.*?)}})', $value, $matches)) {
                 for ($i = 0; $i < $count; $i++) {
                     $cfg[$key] = str_replace($matches[0][$i], $cfg[$matches[1][$i]], $value);
                 }
             }
             foreach ($this->valueParsers as $valueParser) {
                 $cfg[$key] = $valueParser($cfg[$key]);
             }
             $temp =& $this->data;
             $exploded = explode('.', $key);
             foreach ($exploded as $segment) {
                 $temp =& $temp[$segment];
             }
             $temp = $cfg[$key];
             unset($temp);
         }
     }
 }
Example #4
0
 public function buildArray()
 {
     $directory = new \RecursiveDirectoryIterator('assets');
     $iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::CHILD_FIRST);
     $tree = [];
     foreach ($iterator as $info) {
         //if (in_array($info->getFilename(), ['.', '..'])) continue;
         if ($iterator->getDepth() >= 2 || !$iterator->isDir() || $iterator->isDot()) {
             continue;
         }
         if ($iterator->getDepth() == 1) {
             $path = $info->isDir() ? [$iterator->getDepth() - 1 => $info->getFilename()] : [$info->getFilename()];
         } else {
             $path = $info->isDir() ? [$info->getFilename() => []] : [$info->getFilename()];
         }
         for ($depth = $iterator->getDepth() - 1; $depth >= 0; $depth--) {
             $path = [$iterator->getSubIterator($depth)->current()->getFilename() => $path];
         }
         $tree = array_merge_recursive($tree, $path);
     }
     $data = array();
     foreach ($tree as $category => $children) {
         foreach ($children as $index => $value) {
             $data[$category][] = $value;
         }
     }
     foreach ($data as $category => $children) {
         $parentId = $this->addEntry($category, '0');
         foreach ($children as $index => $value) {
             $this->addEntry($value, $parentId);
         }
     }
     return $data;
 }
Example #5
0
 /**
  * [setup description]
  * @param  Array  $array
  * @return void
  * @link   http://stackoverflow.com/a/10424516
  */
 protected function setup(array $array)
 {
     $ritit = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));
     $this->arr = array();
     foreach ($ritit as $leafValue) {
         $keys = array();
         foreach (range(0, $ritit->getDepth()) as $depth) {
             $keys[] = $ritit->getSubIterator($depth)->key();
         }
         $this->set(join('.', $keys), $leafValue);
     }
 }
Example #6
0
 /**
  * Liste le répertoire
  * @param string $pPath
  */
 public function __construct($pPath)
 {
     $this->_directory = $pPath;
     $ritit = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pPath), \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($ritit as $splFileInfo) {
         $path = $splFileInfo->isDir() ? array($splFileInfo->getFilename() => array()) : array($splFileInfo->getFilename());
         for ($depth = $ritit->getDepth() - 1; $depth >= 0; $depth--) {
             $path = array($ritit->getSubIterator($depth)->current()->getFilename() => $path);
         }
         $this->_files = array_merge_recursive($this->_files, $path);
     }
 }
 protected function registerContainerParametersRecursive(ContainerBuilder $container, $alias, $config)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($config), \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $value) {
         $path = array();
         for ($i = 0; $i <= $iterator->getDepth(); $i++) {
             $path[] = $iterator->getSubIterator($i)->key();
         }
         $key = $alias . '.' . implode(".", $path);
         $container->setParameter($key, $value);
     }
 }
 private function extractRepositoriesUrls(array $repositories)
 {
     $urls = array();
     $recursiveIteratorRepositories = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($repositories));
     foreach ($recursiveIteratorRepositories as $key => $leaf) {
         if ('url' === $key) {
             $repositoryPosition = $recursiveIteratorRepositories->getSubIterator(0)->key();
             $urls[$repositoryPosition][] = $leaf;
         }
     }
     return $urls;
 }
Example #9
0
 /**
  * Get the wiki root directory files tree
  * @param  string wiki root directory
  * @return array
  */
 public function getNavBar($navPath)
 {
     $recursiveIteratorIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($navPath, \FilesystemIterator::SKIP_DOTS));
     $filesTree = [];
     foreach ($recursiveIteratorIterator as $splFileInfo) {
         $path = $splFileInfo->isDir() ? array($splFileInfo->getFilename() => []) : array($splFileInfo->getFilename());
         for ($depth = $recursiveIteratorIterator->getDepth() - 1; $depth >= 0; $depth--) {
             $path = [$recursiveIteratorIterator->getSubIterator($depth)->current()->getFilename() => $path];
         }
         $filesTree = array_merge_recursive($filesTree, $path);
     }
     return $filesTree;
 }
 /**
  * Converts a multi-dimensional array to dot-notation single dimensional strings
  * Convert:
  *  [
  *      'foo'   =>  [
  *          'bar'   =>  'baz
  *      ],
  *      'baa'   =>  'sheep'
  *  ]
  *
  * TO
  *  [
  *      'foo.bar'   =>  'baz',
  *      'baa'       =>  'sheep'
  *  ]
  *
  * @param $arrayContents
  *
  * @return array
  */
 public function arrayKeyToStringPath($arrayContents)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrayContents));
     $result = [];
     foreach ($iterator as $leafValue) {
         $keys = [];
         foreach (range(0, $iterator->getDepth()) as $depth) {
             $keys[] = $iterator->getSubIterator($depth)->key();
         }
         $result[join(self::SEPARATOR, $keys)] = $leafValue;
     }
     return $result;
 }
Example #11
0
 public function extractKeys($array, $prefix = null)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));
     $keys = [];
     foreach ($iterator as $key => $value) {
         // Build long key name based on parent keys
         for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
             $key = $iterator->getSubIterator($i)->key() . '.' . $key;
         }
         $keys[] = $prefix . "." . $key;
     }
     return $keys;
 }
Example #12
0
 public function flatten()
 {
     $ritit = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->config));
     $result = array();
     foreach ($ritit as $leafValue) {
         $keys = array();
         foreach (range(0, $ritit->getDepth()) as $depth) {
             $keys[] = $ritit->getSubIterator($depth)->key();
         }
         $result[join('.', $keys)] = $leafValue;
     }
     return $result;
 }
Example #13
0
 /**
  * Override response handler to flatten array
  */
 protected function handleResponse($response, OutputInterface $output)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($response));
     $result = [];
     foreach ($iterator as $leafValue) {
         $keys = [];
         foreach (range(0, $iterator->getDepth()) as $depth) {
             $keys[] = $iterator->getSubIterator($depth)->key();
         }
         $result[join('.', $keys)] = $leafValue;
     }
     return parent::handleResponse($result, $output);
 }
Example #14
0
 /**
  * Convert a php nested array to mongo like dot notation
  * @see http://stackoverflow.com/questions/10424335/php-convert-multidimensional-array-to-2d-array-with-dot-notation-keys
  * @param array $array
  * @return array
  */
 public static function compact(array $array)
 {
     $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
     $rVal = [];
     foreach ($iterator as $leafValue) {
         $keys = array();
         foreach (range(0, $iterator->getDepth()) as $depth) {
             $keys[] = $iterator->getSubIterator($depth)->key();
         }
         $rVal[join('.', $keys)] = $leafValue;
     }
     return $rVal;
 }
Example #15
0
 /**
  * @param string $directory 
  */
 public static function getRecursive($directory)
 {
     $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
     $r = array();
     foreach ($recursiveIterator as $splFileInfo) {
         $path = array('children' => array($splFileInfo->getFilename() => array('type' => $splFileInfo->getType())));
         for ($depth = $recursiveIterator->getDepth() - 1; $depth >= 0; $depth--) {
             $path = array('children' => array($recursiveIterator->getSubIterator($depth)->current()->getFilename() => $path));
         }
         $r = array_merge_recursive($r, $path);
     }
     self::deep_ksort($r);
     return $r;
 }
Example #16
0
 /**
  * Find a named route in a given array of routes.
  *
  * @param  string  $name
  * @param  array   $routes
  * @return array
  */
 public static function find($name, $routes)
 {
     if (array_key_exists($name, static::$names)) {
         return static::$names[$name];
     }
     $arrayIterator = new \RecursiveArrayIterator($routes);
     $recursiveIterator = new \RecursiveIteratorIterator($arrayIterator);
     // Since routes can be nested deep within sub-directories, we need to recursively
     // iterate through each directory and gather all of the routes.
     foreach ($recursiveIterator as $iterator) {
         $route = $recursiveIterator->getSubIterator();
         if (isset($route['name']) and $route['name'] == $name) {
             return static::$names[$name] = array($arrayIterator->key() => iterator_to_array($route));
         }
     }
 }
Example #17
0
 /**
  * Constructs a new Config with the specified array as it's internal items.
  *
  * @param array $items Array with the internal items to set.
  */
 public function __construct(array $items = array())
 {
     // Flatten sub arrays as items
     foreach ($items as $key => $value) {
         if (is_array($value)) {
             $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($value));
             foreach ($iterator as $value) {
                 $keys = array($key);
                 foreach (range(0, $iterator->getDepth()) as $depth) {
                     $keys[] = $iterator->getSubIterator($depth)->key();
                 }
                 $items[join('.', $keys)] = $value;
             }
         }
     }
     $this->items = $items;
 }
Example #18
0
function dirDataToJs_navigateFiles($path)
{
    $ritit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
    $r = array();
    foreach ($ritit as $splFileInfo) {
        if (strpos($splFileInfo->getFilename(), '.') === 0) {
            continue;
        }
        $name = $splFileInfo->getFilename();
        $path = $splFileInfo->isDir() ? array('"' . $name . '"' => array()) : array($name);
        for ($depth = $ritit->getDepth() - 1; $depth >= 0; $depth--) {
            $name = $ritit->getSubIterator($depth)->current()->getFilename();
            $path = array('"' . $name . '"' => $path);
        }
        $r = array_merge_recursive($r, $path);
    }
    return dirDataToJs_dressStructure(dirDataToJs_stripQuotesFromKeys($r));
}
Example #19
0
 /**
  * Gets a compound item's children pointers. $alias needs to include the leading '/'.
  * @ToDo - clerify whether this method should be part of filegetters or fetchers.
  */
 public function getChildren($pointer)
 {
     $alias = $this->settings['alias'];
     $ws_url = $this->settings['ws_url'];
     $query_url = $ws_url . 'dmGetCompoundObjectInfo/' . $alias . '/' . $pointer . '/json';
     $item_structure = file_get_contents($query_url);
     $item_structure = json_decode($item_structure, true);
     /* CONTENTdm supports hierarchical books.  "Flatten" structure of hierarchical 
           source books for importing into Islandora since Islandora's Book Solution Pack 
           currently only supports flat books.
        */
     if ($item_structure['type'] == 'Monograph') {
         // flatten document structure
         // hierarchy based on nodes
         $children_pointers = array();
         // Iterator snippet below based on
         // http://stackoverflow.com/a/1019534/850828
         // @ToDo snippet produces duplicate pointers - why?
         $arrIt = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($item_structure));
         foreach ($arrIt as $sub) {
             $subArray = $arrIt->getSubIterator();
             if (isset($subArray['pageptr'])) {
                 $children_pointers[] = $subArray['pageptr'];
             }
         }
         // remove duplicate pointers
         $children_pointers = array_unique($children_pointers);
         // reindex the array.
         $children_pointers = array_values($children_pointers);
     }
     if ($item_structure['type'] == 'Document') {
         if (isset($item_structure['page'])) {
             $children = $item_structure['page'];
         } else {
             return array();
         }
         $children_pointers = array();
         foreach ($children as $child) {
             $children_pointers[] = $child['pageptr'];
         }
     }
     return $children_pointers;
 }
Example #20
0
 /**
  * @param array|null $yaml The array to be flattened. If null assumes $settings.
  *
  * @return array
  */
 public function flattenYaml(array $yaml = null) : array
 {
     if (null === $yaml) {
         $yaml = $this->getSettings();
     }
     if (0 === count($yaml)) {
         return [];
     }
     $rItIt = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($yaml));
     $settings = [];
     foreach ($rItIt as $leafValue) {
         $keys = [];
         foreach (range(0, $rItIt->getDepth()) as $depth) {
             $keys[] = $rItIt->getSubIterator($depth)->key();
         }
         $settings[implode('.', $keys)] = $leafValue;
     }
     return $settings;
 }
Example #21
0
 /**
  * Main lookup loop
  *
  * @param  \RecursiveIteratorIterator $items
  * @param  scalar                     $needle
  * @param  const                      $findBy  mode to find by
  *
  * @return array
  */
 protected function _findLoop(\RecursiveIteratorIterator $items, $needle, $findBy)
 {
     $result = [];
     foreach ($items as $key => $value) {
         $iter_keys = [];
         for ($i = $items->getDepth() - 1; $i > 0; $i--) {
             $iter_keys[] = $items->getSubIterator($i)->key();
         }
         // Value Search
         if ($findBy === parent::FIND_BY_VALUE && $value === $needle) {
             $result[] = ['key' => $key, 'value' => $value, 'depth' => $items->getDepth(), 'parent_keys' => $iter_keys];
         } else {
             if ($findBy === parent::FIND_BY_KEY && $key === $needle) {
                 $result[] = ['key' => $key, 'value' => $value, 'depth' => $items->getDepth(), 'parent_keys' => $iter_keys];
             }
         }
     }
     return $result;
 }
 /**
  * @param array $criteria
  * @return array
  */
 private function findByCriteria(array $criteria)
 {
     $data = $this->findAll();
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($data));
     $outputArray = [];
     foreach ($iterator as $sub) {
         /** @var array|\Traversable $subIterator */
         $subIterator = $iterator->getSubIterator();
         $matched = true;
         foreach ($criteria as $key => $value) {
             if (!array_key_exists($key, $subIterator) || $subIterator[$key] !== $value) {
                 $matched = false;
             }
         }
         if ($matched) {
             $outputArray[] = iterator_to_array($subIterator);
         }
     }
     return $outputArray;
 }
 private function _getTemplateFilesInThemes()
 {
     $output = array();
     $folderParts = explode('/', getcwd());
     array_pop($folderParts);
     $rootThemes = implode('/', $folderParts) . '/themes';
     $ritit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootThemes), RecursiveIteratorIterator::CHILD_FIRST);
     $r = array();
     foreach ($ritit as $splFileInfo) {
         if (strstr($splFileInfo->getFilename(), '.ss')) {
             $path = array();
             for ($depth = $ritit->getDepth() - 1; $depth >= 0; $depth--) {
                 $path[] = $ritit->getSubIterator($depth)->current()->getFilename();
             }
             $fullPath = implode('/', array_reverse($path)) . '/' . $splFileInfo->getFilename();
             $output[$fullPath] = $fullPath;
         }
     }
     asort($output);
     return $output;
 }
Example #24
0
 /**
  * Modification of http://stackoverflow.com/a/10424516
  *
  * @param $a
  * @return array
  */
 function flatten_array($a)
 {
     $ritit = new RecursiveIteratorIterator(new RecursiveArrayIterator($a));
     $result = [];
     foreach ($ritit as $leafValue) {
         $keys = [];
         foreach (range(0, $ritit->getDepth()) as $depth) {
             $keys[] = $ritit->getSubIterator($depth)->key();
         }
         $continuousKeys = [];
         foreach ($keys as $key) {
             if (is_numeric($key)) {
                 break;
             }
             $continuousKeys[] = $key;
         }
         //$result[join('.', $keys)] = $leafValue;
         $dotKeys = join('.', $continuousKeys);
         if (!in_array($dotKeys, $result)) {
             $result[] = $dotKeys;
         }
     }
     return $result;
 }
Example #25
0
    /**
     * Walk through action and its chained actions tree and remove nodes
     * if they are GoTo actions with an unresolved target.
     *
     * Returns null if root node is deleted or updated action overwise.
     *
     * @todo Give appropriate name and make method public
     *
     * @param Zend_Pdf_Action $action
     * @param boolean $refreshPagesHash  Refresh page collection hashes before processing
     * @return Zend_Pdf_Action|null
     */
    protected function _cleanUpAction(Zend_Pdf_Action $action, $refreshPageCollectionHashes = true)
    {
        if ($this->_pageReferences === null  ||  $refreshPageCollectionHashes) {
            $this->_refreshPagesHash();
        }

        // Named target is an action
        if ($action instanceof Zend_Pdf_Action_GoTo  &&
            $this->resolveDestination($action->getDestination(), false) === null) {
            // Action itself is a GoTo action with an unresolved destination
            return null;
        }

        // Walk through child actions
        $iterator = new RecursiveIteratorIterator($action, RecursiveIteratorIterator::SELF_FIRST);

        $actionsToClean        = array();
        $deletionCandidateKeys = array();
        foreach ($iterator as $chainedAction) {
            if ($chainedAction instanceof Zend_Pdf_Action_GoTo  &&
                $this->resolveDestination($chainedAction->getDestination(), false) === null) {
                // Some child action is a GoTo action with an unresolved destination
                // Mark it as a candidate for deletion
                $actionsToClean[]        = $iterator->getSubIterator();
                $deletionCandidateKeys[] = $iterator->getSubIterator()->key();
            }
        }
        foreach ($actionsToClean as $id => $action) {
            unset($action->next[$deletionCandidateKeys[$id]]);
        }

        return $action;
    }
Example #26
0
 public function testExtract()
 {
     $dictionary = new InternalType\DictionaryObject();
     $dictionary->Type = new InternalType\NameObject('Action');
     $dictionary->S = new InternalType\NameObject('GoToR');
     $dictionary->D = new InternalType\StringObject('SomeNamedDestination');
     $action2Dictionary = new InternalType\DictionaryObject();
     $action2Dictionary->Type = new InternalType\NameObject('Action');
     $action2Dictionary->S = new InternalType\NameObject('Thread');
     $action2Dictionary->D = new InternalType\StringObject('NamedDestination 2');
     $action2Dictionary->Next = new InternalType\ArrayObject();
     $dictionary->Next = $action2Dictionary;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('GoTo');
     $leafAction->D = new InternalType\StringObject('NamedDestination 3');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('GoToR');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('GoToE');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Launch');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Thread');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('URI');
     $leafAction->URI = new InternalType\NameObject('http://some_host/');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Sound');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Movie');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Hide');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Named');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('SubmitForm');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('ResetForm');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('ImportData');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('JavaScript');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('SetOCGState');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Rendition');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('Trans');
     $action2Dictionary->Next->items[] = $leafAction;
     $leafAction = new InternalType\DictionaryObject();
     $leafAction->Type = new InternalType\NameObject('Action');
     $leafAction->S = new InternalType\NameObject('GoTo3DView');
     $action2Dictionary->Next->items[] = $leafAction;
     $action = Action\AbstractAction::load($dictionary);
     $actionsToClean = array();
     $deletionCandidateKeys = array();
     $iterator = new \RecursiveIteratorIterator($action, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $chainedAction) {
         if ($chainedAction instanceof Action\GoToAction) {
             $actionsToClean[] = $iterator->getSubIterator();
             $deletionCandidateKeys[] = $iterator->getSubIterator()->key();
         }
     }
     foreach ($actionsToClean as $id => $action) {
         unset($action->next[$deletionCandidateKeys[$id]]);
     }
     $actionsCount = 0;
     $iterator = new \RecursiveIteratorIterator(new Util\RecursivelyIteratableObjectsContainer(array($action)), \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $chainedAction) {
         $actionsCount++;
     }
     $this->assertEquals(18, $actionsCount);
     $action->dumpAction(new ObjectFactory(1));
     $this->assertEquals($action->getResource()->toString(), '<</Type /Action ' . '/S /Thread ' . '/D (NamedDestination 2) ' . '/Next [1 0 R 2 0 R 3 0 R 4 0 R 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 12 0 R 13 0 R 14 0 R 15 0 R 16 0 R 17 0 R ] >>');
 }
 /**
  * Lookup a contact in the global and local directory
  * @param {int} $id The userman user id
  * @param {string} $search search string
  * @param {string} $regexp Regular Expression pattern to replace
  */
 public function lookupMultipleByUserID($id, $search, $regexp = null)
 {
     $contacts = $this->getContactsByUserID($id);
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($contacts));
     $final = array();
     $list = array();
     foreach ($iterator as $key => $value) {
         $value = !empty($regexp) ? preg_replace($regexp, '', $value) : $value;
         $value = trim($value);
         $k = $iterator->getSubIterator(0)->key();
         if (!in_array($k, $list) && !empty($value) && preg_match('/' . $search . '/i', $value)) {
             $final[] = $contacts[$k];
             $list[] = $k;
         }
     }
     return $final;
 }
 /**
  * @throws Exception\RuntimeException
  * @return string
  */
 public function generate()
 {
     $type = $this->type;
     if ($type != self::TYPE_AUTO) {
         $type = $this->getValidatedType($type);
     }
     $value = $this->value;
     if ($type == self::TYPE_AUTO) {
         $type = $this->getAutoDeterminedType($value);
         if ($type == self::TYPE_ARRAY) {
             $rii = new \RecursiveIteratorIterator($it = new \RecursiveArrayIterator($value), \RecursiveIteratorIterator::SELF_FIRST);
             foreach ($rii as $curKey => $curValue) {
                 if (!$curValue instanceof ValueGenerator) {
                     $curValue = new self($curValue, self::TYPE_AUTO, self::OUTPUT_MULTIPLE_LINE, $this->getConstants());
                     $rii->getSubIterator()->offsetSet($curKey, $curValue);
                 }
                 $curValue->setArrayDepth($rii->getDepth());
             }
             $value = $rii->getSubIterator()->getArrayCopy();
         }
     }
     $output = '';
     switch ($type) {
         case self::TYPE_BOOLEAN:
         case self::TYPE_BOOL:
             $output .= $value ? 'true' : 'false';
             break;
         case self::TYPE_STRING:
             $output .= self::escape($value);
             break;
         case self::TYPE_NULL:
             $output .= 'null';
             break;
         case self::TYPE_NUMBER:
         case self::TYPE_INTEGER:
         case self::TYPE_INT:
         case self::TYPE_FLOAT:
         case self::TYPE_DOUBLE:
         case self::TYPE_CONSTANT:
             $output .= $value;
             break;
         case self::TYPE_ARRAY:
             $output .= 'array(';
             $curArrayMultiblock = false;
             if (count($value) > 1) {
                 $curArrayMultiblock = true;
                 if ($this->outputMode == self::OUTPUT_MULTIPLE_LINE) {
                     $output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1);
                 }
             }
             $outputParts = array();
             $noKeyIndex = 0;
             foreach ($value as $n => $v) {
                 /* @var $v ValueGenerator */
                 $v->setArrayDepth($this->arrayDepth + 1);
                 $partV = $v->generate();
                 $short = false;
                 if (is_int($n)) {
                     if ($n === $noKeyIndex) {
                         $short = true;
                         $noKeyIndex++;
                     } else {
                         $noKeyIndex = max($n + 1, $noKeyIndex);
                     }
                 }
                 if ($short) {
                     $outputParts[] = $partV;
                 } else {
                     $outputParts[] = (is_int($n) ? $n : self::escape($n)) . ' => ' . $partV;
                 }
             }
             $padding = $this->outputMode == self::OUTPUT_MULTIPLE_LINE ? self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1) : ' ';
             $output .= implode(',' . $padding, $outputParts);
             if ($curArrayMultiblock == true && $this->outputMode == self::OUTPUT_MULTIPLE_LINE) {
                 $output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1);
             }
             $output .= ')';
             break;
         case self::TYPE_OTHER:
         default:
             throw new Exception\RuntimeException(sprintf('Type "%s" is unknown or cannot be used as property default value.', get_class($value)));
     }
     return $output;
 }
Example #29
0
    /**
     * generate()
     *
     * @return string
     */
    public function generate()
    {
        $type = $this->_type;

        if ($type != self::TYPE_AUTO) {
            $type = $this->_getValidatedType($type);
        }

        $value = $this->_value;

        if ($type == self::TYPE_AUTO) {
            $type = $this->_getAutoDeterminedType($value);

            if ($type == self::TYPE_ARRAY) {
                $rii = new \RecursiveIteratorIterator(
                    $it = new \RecursiveArrayIterator($value),
                    \RecursiveIteratorIterator::SELF_FIRST
                    );
                foreach ($rii as $curKey => $curValue) {
                    if (!$curValue instanceof self) {
                        $curValue = new self(array('value' => $curValue));
                        $rii->getSubIterator()->offsetSet($curKey, $curValue);
                    }
                    $curValue->setArrayDepth($rii->getDepth());
                }
                $value = $rii->getSubIterator()->getArrayCopy();
            }

        }

        $output = '';

        switch ($type) {
            case self::TYPE_BOOLEAN:
            case self::TYPE_BOOL:
                $output .= ( $value ? 'true' : 'false' );
                break;
            case self::TYPE_STRING:
                $output .= "'" . addcslashes($value, "'") . "'";
                break;
            case self::TYPE_NULL:
                $output .= 'null';
                break;
            case self::TYPE_NUMBER:
            case self::TYPE_INTEGER:
            case self::TYPE_INT:
            case self::TYPE_FLOAT:
            case self::TYPE_DOUBLE:
            case self::TYPE_CONSTANT:
                $output .= $value;
                break;
            case self::TYPE_ARRAY:
                $output .= 'array(';
                $curArrayMultiblock = false;
                if (count($value) > 1) {
                    $curArrayMultiblock = true;
                    if ($this->_outputMode == self::OUTPUT_MULTIPLE_LINE) {
                        $output .= self::LINE_FEED . str_repeat($this->_indentation, $this->_arrayDepth+1);
                    }
                }
                $outputParts = array();
                $noKeyIndex = 0;
                foreach ($value as $n => $v) {
                    $v->setArrayDepth($this->_arrayDepth + 1);
                    $partV = $v->generate();
                    if ($n === $noKeyIndex) {
                        $outputParts[] = $partV;
                        $noKeyIndex++;
                    } else {
                        $outputParts[] = (is_int($n) ? $n : "'" . addcslashes($n, "'") . "'") . ' => ' . $partV;
                    }
                }
                $padding = ($this->_outputMode == self::OUTPUT_MULTIPLE_LINE)
                    ? self::LINE_FEED . str_repeat($this->_indentation, $this->_arrayDepth+1)
                    : ' ';
                $output .= implode(',' . $padding, $outputParts);
                if ($curArrayMultiblock == true && $this->_outputMode == self::OUTPUT_MULTIPLE_LINE) {
                    $output .= self::LINE_FEED . str_repeat($this->_indentation, $this->_arrayDepth+1);
                }
                $output .= ')';
                break;
            case self::TYPE_OTHER:
            default:
                throw new Exception\RuntimeException(
                    "Type '".get_class($value)."' is unknown or cannot be used as property default value."
                );
        }

        return $output;
    }
Example #30
0
 /**
  * Returns the HTML code to display a TeamSpeak 3 viewer.
  *
  * @param  TeamSpeak3_Viewer_Interface $viewer
  * @return string
  */
 public function getViewer(TeamSpeak3_Viewer_Interface $viewer)
 {
     $html = $viewer->fetchObject($this);
     $iterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $node) {
         $siblings = array();
         for ($level = 0; $level < $iterator->getDepth(); $level++) {
             $siblings[] = $iterator->getSubIterator($level)->hasNext() ? 1 : 0;
         }
         $siblings[] = !$iterator->getSubIterator($level)->hasNext() ? 1 : 0;
         $html .= $viewer->fetchObject($node, $siblings);
     }
     return $html;
 }