Exemple #1
0
 /**
  * Gets an array of database seeders.
  *
  * @throws \InvalidArgumentException
  * @return AbstractSeed[]
  */
 public function getSeeds()
 {
     if (null === $this->seeds) {
         $config = $this->getConfig();
         $phpFiles = glob($config->getSeedPath() . DIRECTORY_SEPARATOR . '*.php');
         // filter the files to only get the ones that match our naming scheme
         $fileNames = array();
         /** @var AbstractSeed[] $seeds */
         $seeds = array();
         foreach ($phpFiles as $filePath) {
             if (Util::isValidSeedFileName(basename($filePath))) {
                 // convert the filename to a class name
                 $class = pathinfo($filePath, PATHINFO_FILENAME);
                 $fileNames[$class] = basename($filePath);
                 // load the seed file
                 /** @noinspection PhpIncludeInspection */
                 require_once $filePath;
                 if (!class_exists($class)) {
                     throw new \InvalidArgumentException(sprintf('Could not find class "%s" in file "%s"', $class, $filePath));
                 }
                 // instantiate it
                 $seed = new $class($this->getInput(), $this->getOutput());
                 if (!$seed instanceof AbstractSeed) {
                     throw new \InvalidArgumentException(sprintf('The class "%s" in file "%s" must extend \\Phinx\\Seed\\AbstractSeed', $class, $filePath));
                 }
                 $seeds[$class] = $seed;
             }
         }
         ksort($seeds);
         $this->setSeeds($seeds);
     }
     return $this->seeds;
 }