/** * Executes this task. */ public function main() { if ($this->path === null) { throw new BuildException('The path attribute must be specified'); } $check = new AgaviModuleFilesystemCheck(); $check->setConfigDirectory($this->project->getProperty('module.config.directory')); $check->setPath($this->path->getAbsolutePath()); if (!$check->check()) { throw new BuildException('The path attribute must be a valid module base directory'); } /* We don't know whether the module is configured or not here, so load the * values we want properly. */ $this->tryLoadAgavi(); $this->tryBootstrapAgavi(); require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/module.xml', $this->path->getAbsolutePath(), (string) $this->project->getProperty('module.config.directory'))); $actionPath = AgaviToolkit::expandVariables(AgaviToolkit::expandDirectives(AgaviConfig::get(sprintf('modules.%s.agavi.action.path', strtolower($this->path->getName())), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php')), array('moduleName' => $this->path->getName())); $pattern = '#^' . AgaviToolkit::expandVariables(str_replace('\\$\\{actionName\\}', '${actionName}', preg_quote($actionPath, '#')), array('actionName' => '(?P<action_name>.*?)')) . '$#'; $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath())); for (; $iterator->valid(); $iterator->next()) { $rdi = $iterator->getInnerIterator(); if ($rdi->isDot() || !$rdi->isFile()) { continue; } $file = $rdi->getPathname(); if (preg_match($pattern, $file, $matches)) { $this->log(str_replace(DIRECTORY_SEPARATOR, '.', $matches['action_name'])); } } }
/** * Do the job. * Throw exceptions on errors (the job will be retried). */ public function execute() { global $CFG; $tmpdir = $CFG->tempdir; // Default to last weeks time. $time = time() - $CFG->tempdatafoldercleanup * 3600; $dir = new \RecursiveDirectoryIterator($tmpdir); // Show all child nodes prior to their parent. $iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST); // An array of the full path (key) and date last modified. $modifieddateobject = array(); // Get the time modified for each directory node. Nodes will be updated // once a file is deleted, so we need a list of the original values. for ($iter->rewind(); $iter->valid(); $iter->next()) { $node = $iter->getRealPath(); if (!is_readable($node)) { continue; } $modifieddateobject[$node] = $iter->getMTime(); } // Now loop through again and remove old files and directories. for ($iter->rewind(); $iter->valid(); $iter->next()) { $node = $iter->getRealPath(); if (!is_readable($node)) { continue; } // Check if file or directory is older than the given time. if ($modifieddateobject[$node] < $time) { if ($iter->isDir() && !$iter->isDot()) { // Don't attempt to delete the directory if it isn't empty. if (!glob($node . DIRECTORY_SEPARATOR . '*')) { if (@rmdir($node) === false) { mtrace("Failed removing directory '{$node}'."); } } } if ($iter->isFile()) { if (@unlink($node) === false) { mtrace("Failed removing file '{$node}'."); } } } else { // Return the time modified to the original date only for real files. if ($iter->isDir() && !$iter->isDot()) { touch($node, $modifieddateobject[$node]); } } } }
public static function findDirectories($rootDir, $multiMap = true) { if (!is_dir($rootDir)) { throw new \LogicException($rootDir . ' is not a directory'); } $elements = array(); $d = @dir($rootDir); if (!$d) { throw new \LogicException('Directory is not readable'); } $dirs = array(); $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootDir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); while ($it->valid()) { if (!$it->isDir()) { $it->next(); } else { $cur = $it->current(); if ($cur->isDir()) { if ($multiMap) { $dirs[$cur->getPath()][] = $cur->getFilename(); } else { $dirs[] = $cur->getPath(); } } $it->next(); } } return $dirs; }
/** * @param $path * @return mixed|string */ private function getFile($path) { $returnView = $this->viewFolder . $path . '.php'; if (!file_exists($returnView)) { $dir = $path; $dir = explode('/', $dir); unset($dir[count($dir) - 1]); $dir = implode('/', $dir); $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->viewFolder . $dir)); while ($it->valid()) { if (!$it->isDot()) { $cache['SelectView'] = strrev($path); $cache['SelectView'] = explode("/", $cache['SelectView'])[0]; $cache['SelectView'] = strrev($cache['SelectView']); $cache['ReturnView'] = explode(".", $it->key()); unset($cache['ReturnView'][count($cache['ReturnView']) - 1]); $cache['ReturnView'] = implode('.', $cache['ReturnView']); $cache['ReturnView'] = explode("\\", $cache['ReturnView']); $cache['ReturnView'] = $cache['ReturnView'][count($cache['ReturnView']) - 1]; if ($cache['ReturnView'] == $cache['SelectView']) { $returnView = $it->key(); } } $it->next(); } if (!isset($returnView)) { die('Can not find a file matching these arguments: getView("' . $this->getPath($path, TRUE) . '")'); } return $returnView; } }
private function recursive_rmdir($dirname, $followLinks = false) { if (is_dir($dirname) && !is_link($dirname)) { if (!is_writable($dirname)) { throw new Exception('You do not have renaming permissions!'); } $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST); while ($iterator->valid()) { if (!$iterator->isDot()) { if (!$iterator->isWritable()) { throw new Exception(sprintf('Permission Denied: %s.', $iterator->getPathName())); } if ($iterator->isLink() && false === (bool) $followLinks) { $iterator->next(); } if ($iterator->isFile()) { unlink($iterator->getPathName()); } else { if ($iterator->isDir()) { rmdir($iterator->getPathName()); } } } $iterator->next(); } unset($iterator); // Fix for Windows. return rmdir($dirname); } else { throw new Exception(sprintf('Directory %s does not exist!', $dirname)); } }
/** * Get Test Files * * @param null $directory * @param null $excludes * @return array */ public static function getTestFiles($directory = null, $excludes = null) { if (is_array($directory)) { $files = array(); foreach ($directory as $d) { $files = array_merge($files, self::getTestFiles($d, $excludes)); } return array_unique($files); } if ($excludes !== null) { $excludes = self::getTestFiles((array) $excludes); } if ($directory === null || $directory !== realpath($directory)) { $basePath = App::pluginPath('DebugKit') . 'Test' . DS . 'Case' . DS; $directory = str_replace(DS . DS, DS, $basePath . $directory); } $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); $files = array(); while ($it->valid()) { if (!$it->isDot()) { $file = $it->key(); if (preg_match('|Test\\.php$|', $file) && $file !== __FILE__ && !preg_match('|^All.+?\\.php$|', basename($file)) && ($excludes === null || !in_array($file, $excludes))) { $files[] = $file; } } $it->next(); } return $files; }
/** * @throws \Seitenbau\FileSystem\FileSystemException */ public static function copyDir($source, $destination) { if (!is_dir($source)) { throw new FileSystemException('Sourcedir "' . $source . '" does not exists'); } $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST); if (!self::createDirIfNotExists($destination)) { return false; } // Verzeichnis rekursiv durchlaufen while ($iterator->valid()) { if (!$iterator->isDot()) { if ($iterator->current()->isDir()) { // relativen Teil des Pfad auslesen $relDir = str_replace($source, '', $iterator->key()); // Ziel-Verzeichnis erstellen if (!self::createDirIfNotExists($destination . $relDir)) { return false; } } elseif ($iterator->current()->isFile()) { $destinationFile = $destination . str_replace($source, '', $iterator->key()); if (!copy($iterator->key(), $destinationFile)) { return false; } } } $iterator->next(); } return true; }
public function rmdir($path) { if (!$this->isDeletable($path)) { return false; } try { $it = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($this->getSourcePath($path)), \RecursiveIteratorIterator::CHILD_FIRST ); /** * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach * This bug is fixed in PHP 5.5.9 or before * See #8376 */ $it->rewind(); while ($it->valid()) { /** * @var \SplFileInfo $file */ $file = $it->current(); if (in_array($file->getBasename(), array('.', '..'))) { $it->next(); continue; } elseif ($file->isDir()) { rmdir($file->getPathname()); } elseif ($file->isFile() || $file->isLink()) { unlink($file->getPathname()); } $it->next(); } return rmdir($this->getSourcePath($path)); } catch (\UnexpectedValueException $e) { return false; } }
function get_directory_list($settings = false) { $directory = !empty($settings['dir']) ? $settings['dir'] : CLIENT_DIR . "/"; $array = array(); $array['dirs'] = array(); $array['host'] = array(); $array['root'] = array(); if (!is_dir($directory)) { return false; } $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST); // Loop through directories while ($dir->valid()) { try { $file = $dir->current(); ob_start(); echo $file; $data = ob_get_contents(); ob_end_clean(); $data = trim($data); if (basename($data) != '.' && basename($data) != '..') { $array['host'][] = $data; $array['root'][] = str_replace(ROOT_DIR, "", $data); if (is_dir($data) && !in_array($data . "/", $array['dirs'])) { $array['dirs'][] = $data . "/"; } } unset($data); $dir->next(); } catch (UnexpectedValueException $e) { continue; } } return isset($array) ? $array : false; }
/** * Function to start a scan in a directory. * @return Array * @throws DirectoryNotFoundException */ public static function scanDir($parentDirectory) { $occurences = array(array()); //if the directory/file does not exists, then throw and error. if (!file_exists($parentDirectory)) { throw new DirectoryORFileNotFoundException("ERROR: Directory not found!"); } //get the list of all the files inside this directory. $allFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($parentDirectory)); $fileList = array(); //remove (.), (..) and directories from the list of all files so that only files are left. while ($allFiles->valid()) { if (!$allFiles->isDot()) { if (!is_dir($allFiles->key())) { array_push($fileList, $allFiles->key()); } } $allFiles->next(); } $i = 0; foreach ($fileList as $file) { if (pathinfo($file, PATHINFO_EXTENSION) != "php") { continue; } $occurences[$i]['file'] = realpath($file); $occurences[$i]['result'] = Scanner::scanFile($file); $i++; } return $occurences; }
/** * Remove recursively the directory named by dirname. * * @param string $dirname Path to the directory * @param boolean $followLinks Removes symbolic links if set to true * @return boolean True if success otherwise false * @throws Exception When the directory does not exist or permission denied */ public static function rmdir($dirname, $followLinks = false) { if (!is_dir($dirname) && !is_link($dirname)) { throw new Exception(sprintf('Directory %s does not exist', $dirname)); } if (!is_writable($dirname)) { throw new Exception('You do not have renaming permissions'); } $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::CHILD_FIRST); while ($iterator->valid()) { if (!$iterator->isDot()) { if (!$iterator->isWritable()) { throw new Exception(sprintf('Permission denied for %s', $iterator->getPathName())); } if ($iterator->isLink() && false === (bool) $followLinks) { $iterator->next(); continue; } if ($iterator->isFile()) { unlink($iterator->getPathName()); } else { if ($iterator->isDir()) { rmdir($iterator->getPathName()); } } } $iterator->next(); } unset($iterator); return rmdir($dirname); }
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); } }
/** * Executes a specific Selenium System Tests in your machine * * @param string $seleniumPath Optional path to selenium-standalone-server-x.jar * @param string $pathToTestFile Optional name of the test to be run * @param string $suite Optional name of the suite containing the tests, Acceptance by default. * * @return mixed */ public function runTest($pathToTestFile = null, $suite = 'acceptance') { $this->runSelenium(); // Make sure to Run the Build Command to Generate AcceptanceTester $this->_exec("php vendor/bin/codecept build"); if (!$pathToTestFile) { $this->say('Available tests in the system:'); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('tests/' . $suite, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST); $tests = array(); $iterator->rewind(); $i = 1; while ($iterator->valid()) { if (strripos($iterator->getSubPathName(), 'cept.php') || strripos($iterator->getSubPathName(), 'cest.php')) { $this->say('[' . $i . '] ' . $iterator->getSubPathName()); $tests[$i] = $iterator->getSubPathName(); $i++; } $iterator->next(); } $this->say(''); $testNumber = $this->ask('Type the number of the test in the list that you want to run...'); $test = $tests[$testNumber]; } $pathToTestFile = 'tests/' . $suite . '/' . $test; $this->taskCodecept()->test($pathToTestFile)->arg('--steps')->arg('--debug')->run()->stopOnFail(); // Kill selenium server // $this->_exec('curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer'); }
function array_flatten(array $array, $key_separator = '/') { $result = array(); // a stack of strings $keys = array(); $prev_depth = -1; $iter = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::SELF_FIRST); // rewind() is necessary for ($iter->rewind(); $iter->valid(); $iter->next()) { $curr_depth = $iter->getDepth(); $diff_depth = $prev_depth - $curr_depth + 1; //##### TODO: It would be nice to do this with a single function. while ($diff_depth > 0) { array_pop($keys); --$diff_depth; } /* Note: http://bugs.php.net/bug.php?id=52425 array_shift/array_pop: add parameter that tells how many to elements to pop */ array_push($keys, $iter->key()); if (is_scalar($iter->current())) { $result[implode($key_separator, $keys)] = $iter->current(); } $prev_depth = $curr_depth; } return $result; }
private static function is_extension_changed($name) { $name = strtolower($name); $extension_build_dir = ROOT_PATH . DS . 'build' . DS . $name; $extension_path = ROOT_PATH . DS . 'extensions' . DS . $name . '.tar.gz'; if (file_exists($extension_build_dir) && file_exists($extension_path)) { $dir_iterator = new \RecursiveDirectoryIterator($extension_build_dir); /** * @var $iterator \RecursiveDirectoryIterator */ $iterator = new \RecursiveIteratorIterator($dir_iterator); $iterator->rewind(); while ($iterator->valid()) { if (!$iterator->isDot()) { $file = $extension_build_dir . DS . $iterator->getSubPathName(); $phar_file = "phar://{$extension_path}/" . $iterator->getSubPathName(); if (!file_exists($phar_file)) { return true; } else { $build_file_hash = md5(file_get_contents($file)); $phar_file_hash = md5(file_get_contents($phar_file)); if ($build_file_hash != $phar_file_hash) { return true; } } } $iterator->next(); } return false; } else { return false; } }
/** * Do the job. * Throw exceptions on errors (the job will be retried). */ public function execute() { global $CFG; $tmpdir = $CFG->tempdir; // Default to last weeks time. $time = strtotime('-1 week'); $dir = new \RecursiveDirectoryIterator($tmpdir); // Show all child nodes prior to their parent. $iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST); for ($iter->rewind(); $iter->valid(); $iter->next()) { $node = $iter->getRealPath(); if (!is_readable($node)) { continue; } // Check if file or directory is older than the given time. if ($iter->getMTime() < $time) { if ($iter->isDir() && !$iter->isDot()) { // Don't attempt to delete the directory if it isn't empty. if (!glob($node . DIRECTORY_SEPARATOR . '*')) { if (@rmdir($node) === false) { mtrace("Failed removing directory '{$node}'."); } } } if ($iter->isFile()) { if (@unlink($node) === false) { mtrace("Failed removing file '{$node}'."); } } } } }
/** * Executes this task. */ public function main() { if ($this->property === null) { throw new BuildException('The property attribute must be specified'); } if ($this->path === null) { throw new BuildException('The path attribute must be specified'); } $check = new AgaviModuleFilesystemCheck(); $check->setConfigDirectory($this->project->getProperty('module.directory.config')); $check->setPath($this->path->getAbsolutePath()); if (!$check->check()) { throw new BuildException('The path attribute must be a valid module base directory'); } $actions = array(); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath() . DIRECTORY_SEPARATOR . $this->project->getProperty('module.directory.actions'))); for (; $iterator->valid(); $iterator->next()) { $rdi = $iterator->getInnerIterator(); if ($rdi->isDot() || !$rdi->isFile()) { continue; } $file = $rdi->getSubpathname(); if (preg_match('#Action\\.class\\.php$#', $file)) { $actions[] = str_replace(DIRECTORY_SEPARATOR, '.', substr($file, 0, -16)); } } $list = new AgaviArraytostringTransform(); $list->setInput($actions); $list->setDelimiter(' '); $this->project->setUserProperty($this->property, $list->transform()); }
function valid() { if (!parent::valid()) { echo "<ul>\n"; return false; } return true; }
function valid() { echo __METHOD__ . "\n"; if ($this->skip) { $this->skip = false; $this->next(); } return parent::valid(); }
function directoryClear($path) { if (!file_exists($path)) { return; } $it = new RecursiveIteratorIterator(new eraserIterator($path), RecursiveIteratorIterator::CHILD_FIRST); while ($it->valid()) { $it->erase(); $it->next(); } }
public static function GetDirectoryContent($Directory) { $Iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($Directory)); $FilesArray = array(); while ($Iterator->valid()) { if (!$Iterator->isDot()) { $FilesArray[] = array('FileLink' => $Iterator->key(), 'FileName' => $Iterator->getSubPathName()); } $Iterator->next(); } return $FilesArray; }
public static function addTestDirectoryRecursive(PHPUnit_Framework_TestSuite $suite, $directory) { $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); while ($it->valid()) { if (!$it->isDot()) { $file = $it->key(); if (preg_match('|Test\\.php$|', $file) && $file !== __FILE__) { $suite->addTestFile($file); } } $it->next(); } }
protected function countThemePages($path) { $result = 0; $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); $it->setMaxDepth(1); while ($it->valid()) { if (!$it->isDot() && !$it->isDir() && $it->getExtension() == 'htm') { $result++; } $it->next(); } return $result; }
public static function DirectoryContent($Directory, $UserLanguage) { $ReadDirectory = $Directory . str_replace('.language', '', $UserLanguage); $Iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($ReadDirectory)); $FilesArray = array(); while ($Iterator->valid()) { if (!$Iterator->isDot()) { $FilesArray[] = array('FileLink' => $Iterator->key(), 'FileName' => $Iterator->getSubPathName(), 'SmallFileName' => strtolower(str_replace('.language', '', $Iterator->getSubPathName())), 'LinesCount' => File::CountLines($Iterator->key())); } $Iterator->next(); } return $FilesArray; }
protected function execute($arguments = array(), $options = array()) { switch (strtolower($arguments['scm'])) { case 'git': $ignoreFileName = '.gitignore'; $forceAddIgnoreFileCommand = "git add -f "; break; case 'cvs': $ignoreFileName = '.cvsignore'; $forceAddIgnoreFileCommand = "cvs add "; break; default: echo "Not a support SCM. Only GIT and CVS are currently supported."; exit(1); } // config folder ignores $currentIgnore = 'config/' . $ignoreFileName; $ignoreFiles = "ProjectConfiguration.class.php\ndatabases.yml\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); // Cache folder $currentIgnore = 'cache/' . $ignoreFileName; $ignoreFiles = "*\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); // Log folder $currentIgnore = 'log/' . $ignoreFileName; $ignoreFiles = "*\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); // Begin the looping through $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(sfConfig::get('sf_root_dir'))); $ignorePathArray = array(); while ($it->valid()) { // Does it match a model/om, model/map, form/base, filter/base $path = str_replace(DIRECTORY_SEPARATOR, '/', $it->getPath()); if (strpos($path, 'model/om') || strpos($path, 'model/map') || strpos($path, 'form/base') || strpos($path, 'filter/base') || strpos($path, 'doctrine/base') || strpos($path, 'Plugin/base')) { // Since we currently go through every file we only want to get the path once so use it as the key. $ignorePathArray[$it->getPath()] = true; } $it->next(); } // Write the actual ignores to all the found paths foreach ($ignorePathArray as $path => $value) { $currentIgnore = $path . '/' . $ignoreFileName; $ignoreFiles = "*\n"; $this->writeIgnore($currentIgnore, $ignoreFiles, $options['add-ignores'], $forceAddIgnoreFileCommand); } if ($options['add-ignores']) { echo "All set, ignores created and added!\n"; } else { echo "All set, ignores created!\n"; } }
public function valid() { $valid = $this->iterator->valid(); while ($valid) { $filename = $this->iterator->current()->getPathname(); $ext = Fn::fileExtension($filename); if ($ext !== 'original-filename' && is_file($filename . '.original-filename')) { $this->currentFilename = $filename; break; } $this->iterator->next(); $valid = $this->iterator->valid(); } return $valid; }
/** * Looks for files in "core" code pool */ protected function _checkCoreCodePool() { $files = array(); /** @var \RecursiveDirectoryIterator $dir */ $dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->_extensionPath)); while ($dir->valid()) { if (!$dir->isDot() && strpos($dir->getSubPath(), 'app/code/core') !== false) { $files[] = $dir->getSubPathname(); } $dir->next(); } if (!empty($files)) { $this->_addIssue(array('type' => 'corehack', 'comment' => 'Usage of "core" code pool', 'files' => $files, 'occurrences' => count($files))); } }
/** * Searches value inside a multidimensional array, returning its index * * Original function by "giulio provasi" (link below) * * @param mixed|array $haystack * The haystack to search * * @param mixed $needle * The needle we are looking for * * @param mixed|optional $index * Allow to define a specific index where the data will be searched * * @return integer|string * If given needle can be found in given haystack, its index will * be returned. Otherwise, -1 will * * @see http://www.php.net/manual/en/function.array-search.php#97645 */ public static function search($haystack, $needle, $index = NULL) { if (is_null($haystack)) { return -1; } $arrayIterator = new \RecursiveArrayIterator($haystack); $iterator = new \RecursiveIteratorIterator($arrayIterator); while ($iterator->valid()) { if ((isset($index) and $iterator->key() == $index or !isset($index)) and $iterator->current() == $needle) { return $arrayIterator->key(); } $iterator->next(); } return -1; }
public function delete() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $moduleobject = $this->_uses[$this->modeltype]; $db = DB::Instance(); $db->StartTrans(); if ($moduleobject->isLoaded()) { $modulename = $moduleobject->name; $modulelocation = FILE_ROOT . $moduleobject->location; if ($moduleobject->enabled && !$moduleobject->disable()) { $errors[] = 'Failed to disable module'; } if ($moduleobject->registered && !$moduleobject->unregister()) { $errors[] = 'Failed to unregister module'; } if (!$moduleobject->delete()) { $errors[] = 'Failed to delete module'; } else { $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($modulelocation), RecursiveIteratorIterator::CHILD_FIRST); for ($dir->rewind(); $dir->valid(); $dir->next()) { if ($dir->isDir()) { rmdir($dir->getPathname()); } else { unlink($dir->getPathname()); } } rmdir($modulelocation); } } else { $errors[] = 'Cannot find module'; } $flash = Flash::Instance(); if (count($errors) > 0) { $db->FailTrans(); $flash->addErrors($errors); if (isset($this->_data['id'])) { $db->CompleteTrans(); sendTo($this->name, 'view', $this->_modules, array('id' => $this->_data['id'])); } } else { $flash->addMessage('Module ' . $modulename . ' deleted OK'); } $db->CompleteTrans(); sendTo($this->name, 'index', $this->_modules); }
public static function suite() { $suite = new PHPUnit_Framework_TestSuite('Test Suite'); $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/Test')); for ($it->rewind(); $it->valid(); $it->next()) { // Something like: Test\Application\Modules\Main\Controllers\Index.php $path = "Test\\" . $it->getInnerIterator()->getSubPathname(); // Replace all of the \ with _ $className = str_replace('\\', "_", $path); // Take off the extension $className = substr($className, 0, -4); require_once $path; $suite->addTestSuite($className); } return $suite; }