Exemplo n.º 1
0
use Phalcon\Commands\CommandsListener;
use Phalcon\Loader;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Exception as PhalconException;
try {
    if (!extension_loaded('phalcon')) {
        throw new Exception("Phalcon extension isn't installed, follow these instructions to install it: " . 'https://docs.phalconphp.com/en/latest/reference/install.html');
    }
    $loader = new Loader();
    $loader->registerDirs(array(__DIR__ . '/scripts/'))->registerNamespaces(array('Phalcon' => __DIR__ . '/scripts/'))->register();
    if (Version::getId() < Script::COMPATIBLE_VERSION) {
        throw new Exception(sprintf("Your Phalcon version isn't compatible with Developer Tools, download the latest at: %s", Script::DOC_DOWNLOAD_URL));
    }
    defined('TEMPLATE_PATH') || define('TEMPLATE_PATH', __DIR__ . '/templates');
    $vendor = sprintf('Phalcon DevTools (%s)', Version::get());
    print PHP_EOL . Color::colorize($vendor, Color::FG_GREEN, Color::AT_BOLD) . PHP_EOL . PHP_EOL;
    $eventsManager = new EventsManager();
    $eventsManager->attach('command', new CommandsListener());
    $script = new Script($eventsManager);
    $commandsToEnable = array('\\Phalcon\\Commands\\Builtin\\Enumerate', '\\Phalcon\\Commands\\Builtin\\Controller', '\\Phalcon\\Commands\\Builtin\\Module', '\\Phalcon\\Commands\\Builtin\\Model', '\\Phalcon\\Commands\\Builtin\\AllModels', '\\Phalcon\\Commands\\Builtin\\Project', '\\Phalcon\\Commands\\Builtin\\Scaffold', '\\Phalcon\\Commands\\Builtin\\Migration', '\\Phalcon\\Commands\\Builtin\\Webtools');
    foreach ($commandsToEnable as $command) {
        $script->attach(new $command($script, $eventsManager));
    }
    $script->run();
} catch (PhalconException $e) {
    fwrite(STDERR, Color::error($e->getMessage()) . PHP_EOL);
    exit(1);
} catch (Exception $e) {
    fwrite(STDERR, 'ERROR: ' . $e->getMessage() . PHP_EOL);
    exit(1);
}
Exemplo n.º 2
0
        $extensionLoaded = false;
        include dirname(__FILE__) . '/scripts/Phalcon/Script.php';
        throw new Exception(sprintf("Phalcon extension isn't installed, follow these instructions to install it: %s", Script::DOC_INSTALL_URL));
    }
    $loader = new Loader();
    $loader->registerDirs(array(__DIR__ . '/scripts/'))->registerNamespaces(array('Phalcon' => __DIR__ . '/scripts/'))->register();
    if (Version::getId() < Script::COMPATIBLE_VERSION) {
        throw new Exception(sprintf("Your Phalcon version isn't compatible with Developer Tools, download the latest at: %s", Script::DOC_DOWNLOAD_URL));
    }
    if (!defined('TEMPLATE_PATH')) {
        define('TEMPLATE_PATH', __DIR__ . '/templates');
    }
    $vendor = sprintf('Phalcon DevTools (%s)', Version::get());
    print PHP_EOL . Color::colorize($vendor, Color::FG_GREEN, Color::AT_BOLD) . PHP_EOL . PHP_EOL;
    $eventsManager = new EventsManager();
    $eventsManager->attach('command', new CommandsListener());
    $script = new Script($eventsManager);
    $commandsToEnable = array('\\Phalcon\\Commands\\Builtin\\Enumerate', '\\Phalcon\\Commands\\Builtin\\Controller', '\\Phalcon\\Commands\\Builtin\\Model', '\\Phalcon\\Commands\\Builtin\\AllModels', '\\Phalcon\\Commands\\Builtin\\Project', '\\Phalcon\\Commands\\Builtin\\Scaffold', '\\Phalcon\\Commands\\Builtin\\Migration', '\\Phalcon\\Commands\\Builtin\\Webtools');
    foreach ($commandsToEnable as $command) {
        $script->attach(new $command($script, $eventsManager));
    }
    $script->run();
} catch (PhalconException $e) {
    print Color::error($e->getMessage()) . PHP_EOL;
} catch (Exception $e) {
    if ($extensionLoaded) {
        print Color::error($e->getMessage()) . PHP_EOL;
    } else {
        print 'ERROR: ' . $e->getMessage() . PHP_EOL;
    }
}
Exemplo n.º 3
0
 /**
  * List migrations along with statuses
  *
  * @param array $options
  *
  * @throws Exception
  * @throws ModelException
  * @throws ScriptException
  *
  */
 public static function listAll(array $options)
 {
     // Define versioning type to be used
     if (true === $options['tsBased']) {
         VersionCollection::setType(VersionCollection::TYPE_TIMESTAMPED);
     } else {
         VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL);
     }
     $migrationsDir = rtrim($options['migrationsDir'], '/');
     if (!file_exists($migrationsDir)) {
         throw new ModelException('Migrations directory was not found.');
     }
     /** @var Config $config */
     $config = $options['config'];
     if (!$config instanceof Config) {
         throw new ModelException('Internal error. Config should be an instance of \\Phalcon\\Config');
     }
     // Init ModelMigration
     if (!isset($config->database)) {
         throw new ScriptException('Cannot load database configuration');
     }
     $finalVersion = null;
     if (isset($options['version']) && $options['version'] !== null) {
         $finalVersion = VersionCollection::createItem($options['version']);
     }
     $versionItems = ModelMigration::scanForVersions($migrationsDir);
     if (!isset($versionItems[0])) {
         throw new ModelException('Migrations were not found at ' . $migrationsDir);
     }
     // Set default final version
     if ($finalVersion === null) {
         $finalVersion = VersionCollection::maximum($versionItems);
     }
     ModelMigration::setup($config->database);
     ModelMigration::setMigrationPath($migrationsDir);
     self::connectionSetup($options);
     $initialVersion = self::getCurrentVersion($options);
     $completedVersions = self::getCompletedVersions($options);
     if ($finalVersion->getStamp() < $initialVersion->getStamp()) {
         $direction = ModelMigration::DIRECTION_BACK;
         $versionItems = VersionCollection::sortDesc($versionItems);
     } else {
         $direction = ModelMigration::DIRECTION_FORWARD;
         $versionItems = VersionCollection::sortAsc($versionItems);
     }
     foreach ($versionItems as $versionItem) {
         if (ModelMigration::DIRECTION_FORWARD === $direction && isset($completedVersions[(string) $versionItem])) {
             print Color::success('Version ' . (string) $versionItem . ' was already applied');
             continue;
         } elseif (ModelMigration::DIRECTION_BACK === $direction && !isset($completedVersions[(string) $versionItem])) {
             print Color::success('Version ' . (string) $versionItem . ' was already rolled back');
             continue;
         }
         if (ModelMigration::DIRECTION_FORWARD === $direction) {
             print Color::error('Version ' . (string) $versionItem . ' was not applied');
             continue;
         } elseif (ModelMigration::DIRECTION_BACK === $direction) {
             print Color::error('Version ' . (string) $versionItem . ' was not rolled back');
             continue;
         }
     }
 }