RecursiveIteratorIterator PHP Class Code Examples

This page contains top rated real world PHP examples of class RecursiveIteratorIterator extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: Rule.php Project: mrcoco/SimpleAcl
0
 /**
  * Check owing Role & Resource (and their children) and match its with $roleName & $resourceName;
  * if match was found depending on action allow or deny access to $resourceName for $roleName.
  *
  * @param $needRuleName
  * @param string $needRoleName
  * @param string $needResourceName
  *
  * @return RuleResult|null null is returned if there is no matched Role & Resource in this rule.
  *                         RuleResult otherwise.
  */
 public function isAllowed($needRuleName, $needRoleName, $needResourceName)
 {
     if ($this->isRuleMatched($needRuleName)) {
         if (!is_null($this->getRole())) {
             $roles = new RecursiveIteratorIterator($this->getRole(), RecursiveIteratorIterator::SELF_FIRST);
         } else {
             $roles = array(null);
         }
         if (!is_null($this->getResource())) {
             $resources = new RecursiveIteratorIterator($this->getResource(), RecursiveIteratorIterator::SELF_FIRST);
         } else {
             $resources = array(null);
         }
         foreach ($roles as $role) {
             foreach ($resources as $resource) {
                 $roleDepth = $role ? $roles->getDepth() : 0;
                 $resourceDepth = $resource ? $resources->getDepth() : 0;
                 $depth = $roleDepth + $resourceDepth;
                 $result = $this->match($role, $resource, $needRoleName, $needResourceName, -$depth);
                 if ($result) {
                     return $result;
                 }
             }
         }
     }
     return null;
 }
Example #2
Show file File: LegkoXMLTestCase.php Project: irfan-blackhawk/XSD-to-PHP
0
 protected function assertDirContentsEquals($expDir, $actDir)
 {
     if (!file_exists($expDir)) {
         throw new RuntimeException("Expected dir not found: " . $expDir);
     }
     if (!file_exists($actDir)) {
         throw new RuntimeException("Actual dir not found: " . $actDir);
     }
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($expDir));
     $expFiles = array();
     while ($dir->valid()) {
         if (!$dir->isDot()) {
             array_push($expFiles, $dir->getSubPathName());
         }
         $dir->next();
     }
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($actDir));
     $actFiles = array();
     while ($dir->valid()) {
         if (!$dir->isDot()) {
             array_push($actFiles, $dir->getSubPathName());
         }
         $dir->next();
     }
     $this->assertEquals($expFiles, $actFiles);
     foreach ($expFiles as $key => $value) {
         $expFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $value);
         $actFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $actFiles[$key]);
         $this->assertEquals($expFile, $actFile);
     }
 }
Example #3
Show file File: AddOn.php Project: Sywooch/forums
0
 /**
  * Exports an add-on's XML data.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionZip()
 {
     $addOnId = $this->_input->filterSingle('addon_id', XenForo_Input::STRING);
     $addOn = $this->_getAddOnOrError($addOnId);
     $rootDir = XenForo_Application::getInstance()->getRootDir();
     $zipPath = XenForo_Helper_File::getTempDir() . '/addon-' . $addOnId . '.zip';
     if (file_exists($zipPath)) {
         unlink($zipPath);
     }
     $zip = new ZipArchive();
     $res = $zip->open($zipPath, ZipArchive::CREATE);
     if ($res === TRUE) {
         $zip->addFromString('addon-' . $addOnId . '.xml', $this->_getAddOnModel()->getAddOnXml($addOn)->saveXml());
         if (is_dir($rootDir . '/library/' . $addOnId)) {
             $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/library/' . $addOnId));
             foreach ($iterator as $key => $value) {
                 $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key));
             }
         }
         if (is_dir($rootDir . '/js/' . strtolower($addOnId))) {
             $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/js/' . strtolower($addOnId)));
             foreach ($iterator as $key => $value) {
                 $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key));
             }
         }
         $zip->close();
     }
     if (!file_exists($zipPath) || !is_readable($zipPath)) {
         return $this->responseError(new XenForo_Phrase('devkit_error_while_creating_zip'));
     }
     $this->_routeMatch->setResponseType('raw');
     $attachment = array('filename' => 'addon-' . $addOnId . '_' . $addOn['version_string'] . '.zip', 'file_size' => filesize($zipPath), 'attach_date' => XenForo_Application::$time);
     $viewParams = array('attachment' => $attachment, 'attachmentFile' => $zipPath);
     return $this->responseView('XenForo_ViewAdmin_Attachment_View', '', $viewParams);
 }
Example #4
Show file File: Rollback.php Project: pradeep-wagento/magento2
0
 /**
  * Unzip specified archive
  *
  * @param string $backupFilePath
  * @throws \RuntimeException
  * @return $this
  */
 private function unzipArchive($backupFilePath)
 {
     $phar = new \PharData($backupFilePath);
     $tarFile = str_replace('.tgz', '.tar', $backupFilePath);
     if (@file_exists($tarFile)) {
         @unlink($tarFile);
     }
     $phar->decompress();
     $tar = new \PharData($tarFile);
     if (strpos($backupFilePath, BackupInfo::BACKUP_MEDIA) > 0) {
         $this->deleteDirectory($this->restoreTargetDir . '/pub/media');
     } elseif (strpos($backupFilePath, BackupInfo::BACKUP_CODE) > 0) {
         $blackListFolders = $this->backupInfo->getBlacklist();
         $exclusions = [];
         foreach ($blackListFolders as $blackListFolder) {
             $exclusions[] = $this->restoreTargetDir . '/' . $blackListFolder;
         }
         try {
             $this->deleteDirectory($this->restoreTargetDir, $exclusions);
         } catch (\Exception $e) {
             $this->status->setUpdateError();
             $this->status->add('Error during rollback ' . $e->getMessage(), \Psr\Log\LogLevel::ERROR);
         }
     } else {
         $this->status->setUpdateError();
         $this->status->add('Invalid backup type', \Psr\Log\LogLevel::INFO);
     }
     $tar->extractTo($this->restoreTargetDir, null, true);
     @unlink($tarFile);
     //TODO Temporary solution, can be removed when MAGETWO-38589 is fixed.
     if (strpos($backupFilePath, BackupInfo::BACKUP_MEDIA) > 0) {
         $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->restoreTargetDir . '/pub/media'), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($iterator as $item) {
             @chmod($item, 0777);
         }
     } elseif (strpos($backupFilePath, BackupInfo::BACKUP_CODE) > 0) {
         $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->restoreTargetDir), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($iterator as $item) {
             @chmod($item, 0755);
         }
         $writeAccessFolders = ['/pub/media', '/pub/static', '/var'];
         foreach ($writeAccessFolders as $folder) {
             if (file_exists($this->restoreTargetDir . $folder)) {
                 $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->restoreTargetDir . $folder), \RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($iterator as $item) {
                     @chmod($item, 0777);
                 }
             }
         }
     }
     //TODO Till here
 }
Example #5
Show file File: Filesystem.php Project: onedaylabs/onedaylabs.com
0
 /**
  * Mirrors a directory to another.
  *
  * @param string      $originDir The origin directory
  * @param string      $targetDir The target directory
  * @param Traversable $iterator  A Traversable instance
  * @param array       $options   An array of boolean options
  *                               Valid options are:
  *                               - $options['override'] Whether to override an existing file on copy or not (see copy())
  *                               - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink())
  *                               - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
  *
  * @throws Symfony_Filesystem_Exception_IOException When file type is unknown
  */
 public function mirror($originDir, $targetDir, Traversable $iterator = null, $options = array())
 {
     $targetDir = rtrim($targetDir, '/\\');
     $originDir = rtrim($originDir, '/\\');
     // Iterate in destination folder to remove obsolete entries
     if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
         $deleteIterator = $iterator;
         if (null === $deleteIterator) {
             $flags = Symfony_Filesystem_FilesystemIterator::SKIP_DOTS;
             $deleteIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($targetDir, $flags), RecursiveIteratorIterator::CHILD_FIRST);
         }
         /** @var SplFileObject $file */
         foreach ($deleteIterator as $file) {
             $origin = str_replace($targetDir, $originDir, $file->getPathname());
             if (!$this->exists($origin)) {
                 $this->remove($file);
             }
         }
     }
     $copyOnWindows = false;
     if (isset($options['copy_on_windows']) && !function_exists('symlink')) {
         $copyOnWindows = $options['copy_on_windows'];
     }
     if (null === $iterator) {
         $flags = $copyOnWindows ? Symfony_Filesystem_FilesystemIterator::SKIP_DOTS | Symfony_Filesystem_FilesystemIterator::FOLLOW_SYMLINKS : Symfony_Filesystem_FilesystemIterator::SKIP_DOTS;
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($originDir, $flags), RecursiveIteratorIterator::SELF_FIRST);
     }
     foreach ($iterator as $file) {
         $target = str_replace($originDir, $targetDir, $file->getPathname());
         if ($copyOnWindows) {
             if (is_link($file) || is_file($file)) {
                 $this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
             } elseif (is_dir($file)) {
                 $this->mkdir($target);
             } else {
                 throw new Symfony_Filesystem_Exception_IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
             }
         } else {
             if (is_link($file)) {
                 $this->symlink($file, $target);
             } elseif (is_dir($file)) {
                 $this->mkdir($target);
             } elseif (is_file($file)) {
                 $this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
             } else {
                 throw new Symfony_Filesystem_Exception_IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
             }
         }
     }
 }
Example #6
Show file File: Container.php Project: sonicmaster/RPG
0
 /**
  * Finder method to be able to find resources by context name
  * and attributes.  Example usage:
  *
  * <code>
  *
  * </code>
  *
  * @param Zend_Tool_Project_Profile_Resource_SearchConstraints|string|array $searchParameters
  * @return Zend_Tool_Project_Profile_Resource
  */
 public function search($matchSearchConstraints, $nonMatchSearchConstraints = null)
 {
     if (!$matchSearchConstraints instanceof Zend_Tool_Project_Profile_Resource_SearchConstraints) {
         $matchSearchConstraints = new Zend_Tool_Project_Profile_Resource_SearchConstraints($matchSearchConstraints);
     }
     $this->rewind();
     /**
      * @todo This should be re-written with better support for a filter iterator, its the way to go
      */
     if ($nonMatchSearchConstraints) {
         $filterIterator = new Zend_Tool_Project_Profile_Iterator_ContextFilter($this, array('denyNames' => $nonMatchSearchConstraints));
         $riIterator = new RecursiveIteratorIterator($filterIterator, RecursiveIteratorIterator::SELF_FIRST);
     } else {
         $riIterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
     }
     $foundResource = false;
     $currentConstraint = $matchSearchConstraints->getConstraint();
     $foundDepth = 0;
     foreach ($riIterator as $currentResource) {
         // if current depth is less than found depth, end
         if ($riIterator->getDepth() < $foundDepth) {
             break;
         }
         if (strtolower($currentResource->getName()) == strtolower($currentConstraint->name)) {
             $paramsMatch = true;
             // @todo check to ensure params match (perhaps)
             if (count($currentConstraint->params) > 0) {
                 $currentResourceAttributes = $currentResource->getAttributes();
                 if (!is_array($currentConstraint->params)) {
                     require_once 'Zend/Tool/Project/Profile/Exception.php';
                     throw new Zend_Tool_Project_Profile_Exception('Search parameter specifics must be in the form of an array for key "' . $currentConstraint->name . '"');
                 }
                 foreach ($currentConstraint->params as $paramName => $paramValue) {
                     if (!isset($currentResourceAttributes[$paramName]) || $currentResourceAttributes[$paramName] != $paramValue) {
                         $paramsMatch = false;
                         break;
                     }
                 }
             }
             if ($paramsMatch) {
                 $foundDepth = $riIterator->getDepth();
                 if (($currentConstraint = $matchSearchConstraints->getConstraint()) == null) {
                     $foundResource = $currentResource;
                     break;
                 }
             }
         }
     }
     return $foundResource;
 }