getClassNameFromFile($definition->path); if ($className == '') { $status = MigrationDefinition::STATUS_INVALID; $message = 'The migration definition file should contain a valid class name. The class name is the part of the filename after the 1st underscore'; } else { // we use smart parsing instead before plain file inclusion, by usage of nikic/php-parser // this should help with broken php migrations $pf = new ParserFactory(); $parser = $pf->create(ParserFactory::PREFER_PHP7); try { $parser->parse(file_get_contents($definition->path)); include_once($definition->path); if (!class_exists($className)) { $status = MigrationDefinition::STATUS_INVALID; $message = "The migration definition file should contain a valid class '$className'"; } else { $interfaces = class_implements($className); if (!in_array($this->mandatoryInterface, $interfaces)) { $status = MigrationDefinition::STATUS_INVALID; $message = "The migration definition class '$className' should implement the interface '{$this->mandatoryInterface}'"; } } } catch (Error $e) { $status = MigrationDefinition::STATUS_INVALID; $message = "The migration definition file '{$definition->path}' is not valid php'"; } } if ($status != MigrationDefinition::STATUS_PARSED) { return new MigrationDefinition( $definition->name, $definition->path, $definition->rawDefinition, $status, array(), $message ); } return new MigrationDefinition( $definition->name, $definition->path, $definition->rawDefinition, MigrationDefinition::STATUS_PARSED, array( new MigrationStep('php', array('class' => $className), array('path' => $definition->path)) ) ); } /** * @param string $fileName * @return string|null */ protected function getClassNameFromFile($fileName) { $parts = explode('_', pathinfo($fileName, PATHINFO_FILENAME), 2); return isset($parts[1]) ? $parts[1] : null; } }