Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fraggles = (include __DIR__ . '/../../../examples/fraggles.php');
     $arrayIterator = new \ArrayIterator($fraggles);
     // Print the array
     $output->writeln("The array in natural order");
     foreach ($arrayIterator as $thisFraggle) {
         $output->writeln("  " . $thisFraggle);
     }
     // print the array sorted
     $output->writeln("The array in alphabetical order");
     $arrayIterator->asort();
     foreach ($arrayIterator as $thisFraggle) {
         $output->writeln("  " . $thisFraggle);
     }
     // print the array sorted
     $output->writeln("Emprorer First order");
     $arrayIterator->uasort([$this, 'emperorFirst']);
     foreach ($arrayIterator as $thisFraggle) {
         $output->writeln("  " . $thisFraggle);
     }
     $output->writeln("Done");
     return;
 }
Ejemplo n.º 2
0
 /**
  * @param bool $all
  * @return \ArrayIterator
  */
 public function getMigrationClasses($all = false)
 {
     $classes = new \ArrayIterator();
     $sModuleDir = __DIR__ . "/../../../../../../module";
     //        var_dump(file_exists($sModuleDir));
     $aMigrationDir = array();
     //        if(file_exists($sModuleDir)){
     //            foreach (new \DirectoryIterator($sModuleDir) as $fileInfo) {
     //                if($fileInfo->isDot()) continue;
     //                if(!$fileInfo->isDir()) continue;
     //                $sDirTmp = $sModuleDir."/".$fileInfo->getFilename()."/migrations";
     //                if(file_exists($sDirTmp)){
     //                    $aMigrationDir[] = $sDirTmp;
     //                }
     //            }
     //
     //        }
     $aMigrationDir[] = $this->migrationsDir;
     //        var_dump($aMigrationDir);
     foreach ($aMigrationDir as $sDirTmp) {
         $iterator = new \GlobIterator(sprintf('%s/Version*.php', $sDirTmp), \FilesystemIterator::KEY_AS_FILENAME);
         foreach ($iterator as $item) {
             /** @var $item \SplFileInfo */
             if (preg_match('/(Version(\\d+))\\.php/', $item->getFilename(), $matches)) {
                 $applied = $this->migrationVersionTable->applied($matches[2], $this->migrationsDirMd5);
                 if ($all || !$applied) {
                     $className = $this->migrationsNamespace . '\\' . $matches[1];
                     if (!class_exists($className)) {
                         /** @noinspection PhpIncludeInspection */
                         require_once $sDirTmp . '/' . $item->getFilename();
                     }
                     if (class_exists($className)) {
                         $reflectionClass = new \ReflectionClass($className);
                         $reflectionDescription = new \ReflectionProperty($className, 'description');
                         if ($reflectionClass->implementsInterface('YcheukfMigration\\Library\\MigrationInterface')) {
                             $classes->append(array('version' => $matches[2], 'class' => $className, 'description' => $reflectionDescription->getValue(), 'applied' => $applied));
                         }
                     }
                 }
             }
         }
     }
     //var_dump($classes);
     //exit;
     $classes->uasort(function ($a, $b) {
         if ($a['version'] == $b['version']) {
             return 0;
         }
         return $a['version'] < $b['version'] ? -1 : 1;
     });
     return $classes;
 }
Ejemplo n.º 3
0
 public function uasort($cmp_function)
 {
     parent::uasort($cmp_function);
     $this->refreshPositions();
 }
Ejemplo n.º 4
0
 /**
  * Найти список классов миграций
  * @return \ArrayIterator [version,class]
  */
 public function getMigrationClasses()
 {
     $classes = new \ArrayIterator();
     $iterator = new \GlobIterator(sprintf('%s/Version*.php', $this->migrationClassFolder), \FilesystemIterator::KEY_AS_FILENAME);
     foreach ($iterator as $item) {
         if (preg_match('/(Version(\\d+))\\.php/', $item->getFilename(), $matches)) {
             $className = $this->namespaceMigrationsClasses . '\\' . $matches[1];
             if (!class_exists($className)) {
                 require_once $this->migrationClassFolder . '/' . $item->getFilename();
             }
             if (class_exists($className)) {
                 $reflection = new \ReflectionClass($className);
                 if ($reflection->implementsInterface('ZendDbMigrations\\Library\\MigrationInterface')) {
                     $classes->append(array('version' => $matches[2], 'class' => $className));
                 }
             }
         }
     }
     $classes->uasort(function ($a, $b) {
         if ($a['version'] == $b['version']) {
             return 0;
         }
         return $a['version'] < $b['version'] ? -1 : 1;
     });
     return $classes;
 }
 /**
  * @param bool $all
  * @param string $source
  * @return \ArrayIterator
  */
 public function getMigrationClasses($all = false, $source = null)
 {
     $classes = new \ArrayIterator();
     foreach ($this->migrationsDir as $sourceName => $sourceDir) {
         if (!is_null($source) && $sourceName != $source) {
             continue;
         }
         $iterator = new \GlobIterator(sprintf('%s/Version*.php', $sourceDir), \FilesystemIterator::KEY_AS_FILENAME);
         foreach ($iterator as $item) {
             /** @var $item \SplFileInfo */
             if (preg_match('/(Version(\\d+))\\.php/', $item->getFilename(), $matches)) {
                 $applied = $this->migrationVersionTable->applied($matches[2]);
                 if ($all || !$applied) {
                     $className = $this->migrationsNamespace . '\\' . $matches[1];
                     if (!class_exists($className)) {
                         /** @noinspection PhpIncludeInspection */
                         require_once $sourceDir . '/' . $item->getFilename();
                     }
                     if (class_exists($className)) {
                         $reflectionClass = new \ReflectionClass($className);
                         $reflectionDescription = new \ReflectionProperty($className, 'description');
                         if ($reflectionClass->implementsInterface('ZfSimpleMigrations\\Library\\MigrationInterface')) {
                             $classes->append(['version' => $matches[2], 'class' => $className, 'description' => $reflectionDescription->getValue(), 'applied' => $applied, 'source' => $sourceName]);
                         }
                     }
                 }
             }
         }
     }
     $classes->uasort(function ($a, $b) {
         if ($a['version'] == $b['version']) {
             return 0;
         }
         return $a['version'] < $b['version'] ? -1 : 1;
     });
     return $classes;
 }
Ejemplo n.º 6
0
 /** Build an iterator for this Collection.
  */
 public function getIterator()
 {
     $order = $this->order;
     $iterator = new ArrayIterator($this->collected);
     if (!empty($order)) {
         $desc = $this->desc ? 1 : -1;
         $iterator->uasort(function ($a, $b) use($order, $desc) {
             $a = $a->{$order}();
             $b = $b->{$order}();
             if ($a == $b) {
                 return 0;
             }
             return $a < $b ? $desc : -$desc;
         });
     }
     return $iterator;
 }