本文整理汇总了PHP中Phalcon\Script\Color类的典型用法代码示例。如果您正苦于以下问题:PHP Color类的具体用法?PHP Color怎么用?PHP Color使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Color类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHelp
/**
* {@inheritdoc}
*
* @return void
*/
public function getHelp()
{
print Color::head('Help:') . PHP_EOL;
print Color::colorize(' Creates a module') . PHP_EOL . PHP_EOL;
print Color::head('Example') . PHP_EOL;
print Color::colorize(' phalcon module backend', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
$this->printParameters($this->getPossibleParams());
}
示例2: getHelp
/**
* Prints help on the usage of the command
*
*/
public function getHelp()
{
print Color::head('Help:') . PHP_EOL;
print Color::colorize(' Enables/disables webtools in a project') . PHP_EOL . PHP_EOL;
print Color::head('Usage:') . PHP_EOL;
print Color::colorize(' webtools [action]', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
print Color::head('Arguments:') . PHP_EOL;
print Color::colorize(' ?', Color::FG_GREEN);
print Color::colorize("\tShows this help text") . PHP_EOL . PHP_EOL;
$this->printParameters($this->_possibleParameters);
}
示例3: getHelp
/**
* Prints the help for current command.
*
* @return void
*/
public function getHelp()
{
print Color::head('Help:') . PHP_EOL;
print Color::colorize(' Creates a controller') . PHP_EOL . PHP_EOL;
print Color::head('Usage:') . PHP_EOL;
print Color::colorize(' controller [name] [directory]', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
print Color::head('Arguments:') . PHP_EOL;
print Color::colorize(' ?', Color::FG_GREEN);
print Color::colorize("\tShows this help text") . PHP_EOL . PHP_EOL;
$this->printParameters($this->_possibleParameters);
}
示例4: getHelp
/**
* {@inheritdoc}
*
* @return void
*/
public function getHelp()
{
print Color::head('Help:') . PHP_EOL;
print Color::colorize(' Creates a scaffold from a database table') . PHP_EOL . PHP_EOL;
print Color::head('Usage:') . PHP_EOL;
print Color::colorize(' scaffold [tableName] [options]', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
print Color::head('Arguments:') . PHP_EOL;
print Color::colorize(' help', Color::FG_GREEN);
print Color::colorize("\tShows this help text") . PHP_EOL . PHP_EOL;
$this->printParameters($this->getPossibleParams());
}
示例5: getHelp
/**
* Prints the help for current command.
*
* @return void
*/
public function getHelp()
{
print Color::head('Help:') . PHP_EOL;
print Color::colorize(' Creates a project') . PHP_EOL . PHP_EOL;
print Color::head('Usage:') . PHP_EOL;
print Color::colorize(' project [name] [type] [directory] [enable-webtools]', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
print Color::head('Arguments:') . PHP_EOL;
print Color::colorize(' help', Color::FG_GREEN);
print Color::colorize("\tShows this help text") . PHP_EOL . PHP_EOL;
print Color::head('Example') . PHP_EOL;
print Color::colorize(' phalcon project store simple', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
$this->printParameters($this->_possibleParameters);
}
示例6: build
public function build()
{
$path = '';
if (isset($this->_options['directory'])) {
if ($this->_options['directory']) {
$path = $this->_options['directory'] . '/';
}
}
if (isset($this->_options['templatePath'])) {
$templatePath = $this->_options['templatePath'];
} else {
$templatePath = str_replace('scripts/' . str_replace('\\', DIRECTORY_SEPARATOR, __CLASS__) . '.php', '', __FILE__) . 'templates';
}
if (file_exists($path . '.phalcon')) {
throw new BuilderException("Projects cannot be created inside Phalcon projects");
}
if (isset($this->_options['type'])) {
$type = $this->_options['type'];
if (!isset($this->_types[$type])) {
$keys = array_keys($this->_types);
$keys = implode(" , ", $keys);
throw new BuilderException('Type "' . $type . '" is not a valid type. Choose among [' . $keys . '] ');
}
} else {
$type = 'simple';
}
$name = null;
if (isset($this->_options['name'])) {
if ($this->_options['name']) {
$name = $this->_options['name'];
$path .= $this->_options['name'] . '/';
if (file_exists($path)) {
throw new BuilderException("Directory " . $path . " already exists");
}
mkdir($path);
}
}
if (!is_writable($path)) {
throw new BuilderException("Directory " . $path . " is not writable");
}
$builderClass = $this->_types[$type];
$builder = new $builderClass();
$success = $builder->build($name, $path, $templatePath, $this->_options);
if ($success === true) {
print Color::success('Project "' . $name . '" was successfully created.') . PHP_EOL;
}
return $success;
}
示例7: build
public function build($name, $path, $templatePath, $options)
{
$this->buildDirectories($this->_dirs, $path);
//Disable ini config
// if (isset($options['useConfigIni']))
// $useIniConfig = $options['useConfigIni'];
// else
$useIniConfig = false;
if ($useIniConfig) {
$this->createConfig($path, $templatePath, 'ini');
} else {
$this->createConfig($path, $templatePath, 'php');
}
$this->createBootstrapFiles($path, $templatePath, $useIniConfig);
$this->createDefaultTasks($path, $templatePath);
$this->createLauncher($name, $path, $templatePath);
$pathSymLink = realpath($path . $name);
print Color::success("You can create a symlink to {$pathSymLink} to invoke the application") . PHP_EOL;
return true;
}
示例8: printParameters
/**
* Prints the available options in the script
*
* @param array $parameters
*/
public function printParameters($parameters)
{
$length = 0;
foreach ($parameters as $parameter => $description) {
if ($length == 0) {
$length = strlen($parameter);
}
if (strlen($parameter) > $length) {
$length = strlen($parameter);
}
}
print Color::head('Options:') . PHP_EOL;
foreach ($parameters as $parameter => $description) {
print Color::colorize(' --' . $parameter . str_repeat(' ', $length - strlen($parameter)), Color::FG_GREEN);
print Color::colorize(" " . $description) . PHP_EOL;
}
}
示例9: build
//.........这里部分代码省略.........
$forceProcess = $this->options->get('force');
$defineRelations = $this->options->get('defineRelations', false);
$defineForeignKeys = $this->options->get('foreignKeys', false);
$genSettersGetters = $this->options->get('genSettersGetters', false);
$mapColumn = $this->options->get('mapColumn', null);
$adapter = $config->database->adapter;
$this->isSupportedAdapter($adapter);
$adapter = 'Mysql';
if (isset($config->database->adapter)) {
$adapter = $config->database->adapter;
}
if (is_object($config->database)) {
$configArray = $config->database->toArray();
} else {
$configArray = $config->database;
}
$adapterName = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
unset($configArray['adapter']);
/**
* @var $db \Phalcon\Db\Adapter\Pdo
*/
$db = new $adapterName($configArray);
if ($this->options->contains('schema')) {
$schema = $this->options->get('schema');
} elseif ($adapter == 'Postgresql') {
$schema = 'public';
} else {
$schema = isset($config->database->schema) ? $config->database->schema : $config->database->dbname;
}
$hasMany = array();
$belongsTo = array();
$foreignKeys = array();
if ($defineRelations || $defineForeignKeys) {
foreach ($db->listTables($schema) as $name) {
if ($defineRelations) {
if (!isset($hasMany[$name])) {
$hasMany[$name] = array();
}
if (!isset($belongsTo[$name])) {
$belongsTo[$name] = array();
}
}
if ($defineForeignKeys) {
$foreignKeys[$name] = array();
}
$camelCaseName = Utils::camelize($name);
$refSchema = $adapter != 'Postgresql' ? $schema : $config->database->dbname;
foreach ($db->describeReferences($name, $schema) as $reference) {
$columns = $reference->getColumns();
$referencedColumns = $reference->getReferencedColumns();
$referencedModel = Utils::camelize($reference->getReferencedTable());
if ($defineRelations) {
if ($reference->getReferencedSchema() == $refSchema) {
if (count($columns) == 1) {
$belongsTo[$name][] = array('referencedModel' => $referencedModel, 'fields' => $columns[0], 'relationFields' => $referencedColumns[0], 'options' => $defineForeignKeys ? array('foreignKey' => true) : null);
$hasMany[$reference->getReferencedTable()][] = array('camelizedName' => $camelCaseName, 'fields' => $referencedColumns[0], 'relationFields' => $columns[0]);
}
}
}
}
}
} else {
foreach ($db->listTables($schema) as $name) {
if ($defineRelations) {
$hasMany[$name] = array();
$belongsTo[$name] = array();
$foreignKeys[$name] = array();
}
}
}
foreach ($db->listTables($schema) as $name) {
$className = $this->options->contains('abstract') ? 'Abstract' : '';
$className .= Utils::camelize($name);
if (!file_exists($modelPath . $className . '.php') || $forceProcess) {
if (isset($hasMany[$name])) {
$hasManyModel = $hasMany[$name];
} else {
$hasManyModel = array();
}
if (isset($belongsTo[$name])) {
$belongsToModel = $belongsTo[$name];
} else {
$belongsToModel = array();
}
if (isset($foreignKeys[$name])) {
$foreignKeysModel = $foreignKeys[$name];
} else {
$foreignKeysModel = array();
}
$modelBuilder = new Model(array('name' => $name, 'schema' => $schema, 'extends' => $this->options->get('extends'), 'namespace' => $this->options->get('namespace'), 'force' => $forceProcess, 'hasMany' => $hasManyModel, 'belongsTo' => $belongsToModel, 'foreignKeys' => $foreignKeysModel, 'genSettersGetters' => $genSettersGetters, 'directory' => $this->options->get('directory'), 'modelsDir' => $this->options->get('modelsDir'), 'mapColumn' => $mapColumn, 'abstract' => $this->options->get('abstract')));
$modelBuilder->build();
} else {
if ($this->isConsole()) {
print Color::info(sprintf('Skipping model "%s" because it already exist', Utils::camelize($name)));
} else {
$this->exist[] = $name;
}
}
}
}
示例10: run
/**
* Run migrations
*
* @param array $options
*
* @throws Exception
* @throws ModelException
* @throws ScriptException
*/
public static function run(array $options)
{
$path = $options['directory'];
$migrationsDir = $options['migrationsDir'];
if (!file_exists($migrationsDir)) {
throw new ModelException('Migrations directory could not found.');
}
$config = $options['config'];
if (!$config instanceof Config) {
throw new ModelException('Internal error. Config should be instance of \\Phalcon\\Config');
}
$finalVersion = null;
if (isset($options['version']) && $options['version'] !== null) {
$finalVersion = new VersionItem($options['version']);
}
$tableName = 'all';
if (isset($options['tableName'])) {
$tableName = $options['tableName'];
}
// read all versions
$versions = array();
$iterator = new \DirectoryIterator($migrationsDir);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isDir() && preg_match('/[a-z0-9](\\.[a-z0-9]+)+/', $fileinfo->getFilename(), $matches)) {
$versions[] = new VersionItem($matches[0], 3);
}
}
if (count($versions) == 0) {
throw new ModelException('Migrations were not found at ' . $migrationsDir);
}
// set default final version
if ($finalVersion === null) {
$finalVersion = VersionItem::maximum($versions);
}
// read current version
if (is_file($path . '.phalcon')) {
unlink($path . '.phalcon');
mkdir($path . '.phalcon');
}
$migrationFid = $path . '.phalcon/migration-version';
$initialVersion = new VersionItem(file_exists($migrationFid) ? file_get_contents($migrationFid) : null);
if ($initialVersion->getStamp() == $finalVersion->getStamp()) {
return;
// nothing to do
}
// init ModelMigration
if (!isset($config->database)) {
throw new ScriptException('Cannot load database configuration');
}
ModelMigration::setup($config->database);
ModelMigration::setMigrationPath($migrationsDir);
// run migration
$versionsBetween = VersionItem::between($initialVersion, $finalVersion, $versions);
foreach ($versionsBetween as $k => $version) {
/** @var \Phalcon\Version\Item $version */
if ($tableName == 'all') {
$iterator = new \DirectoryIterator($migrationsDir . '/' . $version);
foreach ($iterator as $fileinfo) {
if (!$fileinfo->isFile() || !preg_match('/\\.php$/i', $fileinfo->getFilename())) {
continue;
}
ModelMigration::migrate($initialVersion, $version, $fileinfo->getBasename('.php'));
}
} else {
ModelMigration::migrate($initialVersion, $version, $tableName);
}
file_put_contents($migrationFid, (string) $version);
print Color::success('Version ' . $version . ' was successfully migrated');
$initialVersion = $version;
}
}
示例11: mainAction
/**
* Initialize task
*/
public function mainAction()
{
// define error handler
$this->setSilentErrorHandler();
try {
// init configurations // init logger
$this->setConfig($this->getDI()->get('config'))->setLogger();
// run server
$this->sonar = new Application($this->getConfig());
$this->sonar->run();
} catch (AppServiceException $e) {
echo Color::colorize($e->getMessage(), Color::FG_RED, Color::AT_BOLD) . PHP_EOL;
if ($this->logger != null) {
// logging all error exceptions
$this->getLogger()->log($e->getMessage(), Logger::CRITICAL);
}
}
}
示例12: build
//.........这里部分代码省略.........
if (isset($this->_options['genSettersGetters'])) {
$genSettersGetters = $this->_options['genSettersGetters'];
} else {
$genSettersGetters = false;
}
$adapter = $config->database->adapter;
$this->isSupportedAdapter($adapter);
if (isset($config->database->adapter)) {
$adapter = $config->database->adapter;
} else {
$adapter = 'Mysql';
}
if (is_object($config->database)) {
$configArray = $config->database->toArray();
} else {
$configArray = $config->database;
}
$adapterName = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
unset($configArray['adapter']);
/**
* @var $db \Phalcon\Db\Adapter\Pdo
*/
$db = new $adapterName($configArray);
if (isset($this->_options['schema'])) {
$schema = $this->_options['schema'];
} elseif ($adapter == 'Postgresql') {
$schema = 'public';
} else {
$schema = isset($config->database->schema) ? $config->database->schema : $config->database->dbname;
}
$hasMany = array();
$belongsTo = array();
$foreignKeys = array();
if ($defineRelations || $defineForeignKeys) {
foreach ($db->listTables($schema) as $name) {
if ($defineRelations) {
if (!isset($hasMany[$name])) {
$hasMany[$name] = array();
}
if (!isset($belongsTo[$name])) {
$belongsTo[$name] = array();
}
}
if ($defineForeignKeys) {
$foreignKeys[$name] = array();
}
$camelCaseName = Utils::camelize($name);
$refSchema = $adapter != 'Postgresql' ? $schema : $config->database->dbname;
foreach ($db->describeReferences($name, $schema) as $reference) {
$columns = $reference->getColumns();
$referencedColumns = $reference->getReferencedColumns();
$referencedModel = Utils::camelize($reference->getReferencedTable());
if ($defineRelations) {
if ($reference->getReferencedSchema() == $refSchema) {
if (count($columns) == 1) {
$belongsTo[$name][] = array('referencedModel' => $referencedModel, 'fields' => $columns[0], 'relationFields' => $referencedColumns[0], 'options' => $defineForeignKeys ? array('foreignKey' => true) : NULL);
$hasMany[$reference->getReferencedTable()][] = array('camelizedName' => $camelCaseName, 'fields' => $referencedColumns[0], 'relationFields' => $columns[0]);
}
}
}
}
}
} else {
foreach ($db->listTables($schema) as $name) {
if ($defineRelations) {
$hasMany[$name] = array();
$belongsTo[$name] = array();
$foreignKeys[$name] = array();
}
}
}
foreach ($db->listTables($schema) as $name) {
$className = Utils::camelize($name);
if (!file_exists($modelsDir . '/' . $className . '.php') || $forceProcess) {
if (isset($hasMany[$name])) {
$hasManyModel = $hasMany[$name];
} else {
$hasManyModel = array();
}
if (isset($belongsTo[$name])) {
$belongsToModel = $belongsTo[$name];
} else {
$belongsToModel = array();
}
if (isset($foreignKeys[$name])) {
$foreignKeysModel = $foreignKeys[$name];
} else {
$foreignKeysModel = array();
}
$modelBuilder = new \Phalcon\Builder\Model(array('name' => $name, 'schema' => $schema, 'extends' => isset($this->_options['extends']) ? $this->_options['extends'] : null, 'namespace' => $this->_options['namespace'], 'force' => $forceProcess, 'hasMany' => $hasManyModel, 'belongsTo' => $belongsToModel, 'foreignKeys' => $foreignKeysModel, 'genSettersGetters' => $genSettersGetters, 'directory' => $this->_options['directory']));
$modelBuilder->build();
} else {
if ($this->isConsole()) {
print Color::info("Skipping model \"{$name}\" because it already exist");
} else {
$this->exist[] = $name;
}
}
}
}
示例13: getHelp
/**
* {@inheritdoc}
*
* @return void
*/
public function getHelp()
{
print Color::head('Help:') . PHP_EOL;
print Color::colorize(' Generates/Run a Migration') . PHP_EOL . PHP_EOL;
print Color::head('Usage: Generate a Migration') . PHP_EOL;
print Color::colorize(' migration generate', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
print Color::head('Usage: Run a Migration') . PHP_EOL;
print Color::colorize(' migration run', Color::FG_GREEN) . PHP_EOL . PHP_EOL;
print Color::head('Arguments:') . PHP_EOL;
print Color::colorize(' help', Color::FG_GREEN);
print Color::colorize("\tShows this help text") . PHP_EOL . PHP_EOL;
$this->printParameters($this->getPossibleParams());
}
示例14: Exception
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);
}
示例15: build
/**
* Build project
*
* @param $name
* @param $path
* @param $templatePath
* @param $options
*
* @return bool
*/
public function build($name, $path, $templatePath, $options)
{
$this->buildDirectories($this->_dirs, $path);
$this->getVariableValues($options);
$this->createConfig($path, $templatePath);
/*if (isset($options['useConfigIni']) && $options['useConfigIni']) {
$this->createConfig($path, $templatePath, 'ini');
} else {
$this->createConfig($path, $templatePath, 'php');
}*/
$this->createBootstrapFiles($path, $templatePath);
$this->createDefaultTasks($path, $templatePath);
$this->createLauncher($name, $path, $templatePath);
$pathSymLink = realpath($path . $name);
print Color::success("You can create a symlink to {$pathSymLink} to invoke the application") . PHP_EOL;
return true;
}