/** * Filter based on class properties * * [ClassIterator](src/Iterator/ClassIterator.php) is filterable and filters * are chainable. * * @expectOutputString Iterator\FilterIterator\NotFilterIterator\ClassIteratorIterator\NotFilter */ public function exampleFilter() { $finder = new Finder(); $iter = new ClassIterator($finder->in('src')); $iter->enableAutoloading(); // Print all Filter types (including the interface itself) foreach ($iter->type('Iterator\\Filter') as $class) { echo $class->getName(); } // Print definitions in the Iterator namespace whose name contains 'Class' foreach ($iter->inNamespace('Iterator')->name('/Class/') as $class) { echo $class->getName(); } // Print implementations of the Filter interface foreach ($iter->type('Iterator\\Filter')->where('isInstantiable') as $class) { echo $class->getName(); } }
public function getAllCacheableClasses() { $finder = new Finder(); $iterator = new ClassIterator($finder->in($this->directory)); $iterator->enableAutoloading(); $classes = []; foreach ($iterator->type(Model::class) as $className => $class) { if ($class->isInstantiable() && $this->usesCaching($class)) { $classes[] = $className; } } return $classes; }
/** * For every model found in the application and all modules checks if audit objects exist and are valid. * @param array $exclude as an array of model names * @return array */ public function getReport($exclude = []) { $finder = new Finder(); $iter = new ClassIterator($finder->in('.')); $iter->enableAutoloading(); $result = $this->getBackendAuditManager()->checkGeneral(); /** @var ReflectionClass $class */ foreach ($iter->type('yii\\db\\ActiveRecord') as $name => $class) { if (in_array($name, $exclude)) { continue; } $result[$name] = $this->getBackendAuditManager()->checkModel(new $name()); } return $result; }
private function getModulesTablesMap() { if ($this->cacheDuration !== null && ($result = \Yii::$app->cache->get(self::CACHE_KEY)) !== false) { return $result; } $ds = DIRECTORY_SEPARATOR; $dirs = [\Yii::$app->getBasePath() . $ds . 'models']; foreach (\Yii::$app->getModules() as $moduleId => $module) { /** @var Module $module */ if (!$module instanceof Module) { $module = \Yii::$app->getModule($moduleId); } if (file_exists($dir = $module->getBasePath() . $ds . 'models')) { $dirs[] = $dir; } } $iterator = new ClassIterator(Finder::create()->files()->name('*.php')->in($dirs)); $iterator->enableAutoloading(); $result = []; /** @var \ReflectionClass $class */ foreach ($iterator->type('yii\\db\\ActiveRecord') as $name => $class) { /** @var \yii\db\ActiveRecord $name */ $name = $class->name; $result[$name::getDb()->quoteSql($name::tableName())] = $name; } if ($this->cacheDuration !== null) { \Yii::$app->cache->set(self::CACHE_KEY, $result, $this->cacheDuration); } return $result; }