本文整理汇总了PHP中Yii::createConsoleApplication方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::createConsoleApplication方法的具体用法?PHP Yii::createConsoleApplication怎么用?PHP Yii::createConsoleApplication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::createConsoleApplication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @param $root
* @param string $configName
* @param mixed $mergeWith
* @return mixed
* @throws Exception
*/
public static function create($root, $configName = 'main', $mergeWith = array('common', 'env'))
{
if (($root = realpath($root)) === false) {
throw new Exception('could not initialize framework.');
}
$config = self::config($configName, $mergeWith);
$class = Config::value('yiinitializr.app.classes.' . $configName);
if ($class && !is_callable($class)) {
throw new Exception('yiinitializr.app.classes.' . $configName . ' class must be callable.');
}
if (php_sapi_name() !== 'cli') {
// aren't we in console?
$app = $class ? $class($config) : \Yii::createWebApplication($config);
} else {
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
$app = $class ? $class($config) : \Yii::createConsoleApplication($config);
$app->commandRunner->addCommands($root . '/cli/commands');
$env = @getenv('YII_CONSOLE_COMMANDS');
if (!empty($env)) {
$app->commandRunner->addCommands($env);
}
}
// return an app
return $app;
}
示例2: createConsoleYiiApp
public function createConsoleYiiApp()
{
require dirname(__FILE__) . '/../../vendor/autoload.php';
$config = (require dirname(__FILE__) . '/../../protected/config/console-test.php');
\Yii::$enableIncludePath = false;
if (!\Yii::app()) {
\Yii::createConsoleApplication($config);
}
}
示例3: initialize
public function initialize()
{
// require_once "vendor/autoload.php";
define('YII_DEBUG', false);
require_once "vendor/yiisoft/yii/framework/yii.php";
$app = Yii::createConsoleApplication(array('basePath' => dirname(__FILE__), 'import' => array('application.models.*')));
Author::$db = Book::$db = $this->db = new CDbConnection('sqlite::memory:');
$this->db->active = true;
Author::createTable();
Book::createTable();
}
示例4: define
<?php
define('YII_PATH', realpath(__DIR__ . '/../../../yiisoft/yii/framework'));
// disable Yii error handling logic
defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER', false);
defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER', false);
define('APP_ROOT', realpath(__DIR__ . '/../../../../app/protected'));
define('APP_RUNTIME', APP_ROOT . '/runtime');
define('APP_ASSETS', APP_ROOT . '/assets');
// composer autoloader
require_once __DIR__ . '/../../../autoload.php';
require_once YII_PATH . '/yii.php';
$env = @getenv('YII_MONGOYII_ENV');
if ($env) {
$env = unserialize($env);
} else {
$env = [];
}
Yii::createConsoleApplication(CMap::mergeArray(['name' => 'test', 'basePath' => APP_ROOT, 'runtimePath' => APP_RUNTIME, 'aliases' => ['mongoyii' => realpath(__DIR__ . '/../')], 'import' => ['mongoyii.*', 'mongoyii.behaviors.*', 'mongoyii.util.*', 'mongoyii.validators.*'], 'components' => ['mongodb' => ['class' => 'mongoyii.EMongoClient', 'db' => 'mongoyii-fake', 'server' => 'mongodb://10.8.4.114:27017'], 'authManager' => ['class' => 'mongoyii.util.EMongoAuthManager']]], $env));
// See the `Boostrap.init()` method for explanation why it is needed
define('IS_IN_TESTS', true);
require_once 'models/User.php';
require_once 'models/UserTsTest.php';
require_once 'models/Interest.php';
require_once 'models/Dummy.php';
require_once 'models/Skill.php';
require_once 'models/versionedDocument.php';
示例5: array
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../vendor/yiisoft/yii/framework/yiit.php';
$config = array('basePath' => __DIR__ . DIRECTORY_SEPARATOR . '..', 'aliases' => ['fakes' => __DIR__ . '/fakes'], 'components' => array('db' => array('class' => '\\Intersvyaz\\ExtendedDb\\DbConnection', 'connectionString' => 'sqlite:' . __DIR__ . DIRECTORY_SEPARATOR . 'test.db')));
Yii::createConsoleApplication($config);
// fix Yii's autoloader (https://github.com/yiisoft/yii/issues/1907)
Yii::$enableIncludePath = false;
Yii::import('fakes.*');
// create DUAL table
$db = new PDO($config['components']['db']['connectionString']);
$db->exec('CREATE TABLE IF NOT EXISTS dual(a PRIMARY KEY)');
$db->exec('insert OR IGNORE into dual values(1)');
unset($db);
示例6:
<?php
require __DIR__ . '/../vendor/autoload.php';
$app = Yii::createConsoleApplication(__DIR__ . '/config/console.php');
$app->commandRunner->addCommands(YII_PATH . '/cli/commands');
$app->run();
示例7: dirname
<?php
/**
* This is the bootstrap file for console application.
*/
// Set environment
require_once dirname(__FILE__) . '/protected/extensions/environment/Environment.php';
$env = new Environment();
$env->init();
Yii::createConsoleApplication($env->console)->run();
// When you execute a PHP script from the command line, it inherits the environment variables defined in your shell.
// That means you can set an environment variable using the export command like so:
// export YII_ENVIRONMENT='TEST'
// Shell: php /path/to/cron.php command
示例8: defined
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
// including Yii
require_once '/framework/yii.php';
// we'll use a separate config file
$configFile = dirname(__FILE__) . '/protected/config/console.php';
// creating and running console application
Yii::createConsoleApplication($configFile)->run();
示例9: mockApplication
/**
* Populates Yii::$app with a new application
*/
protected function mockApplication()
{
static $config = array('id' => 'testapp', 'basePath' => __DIR__);
Yii::createConsoleApplication($config);
Yii::setPathOfAlias('vendor', VENDOR);
}
示例10: getYiiApplication
/**
* Creates console application, if Yii is available
*/
private static function getYiiApplication()
{
if (!is_file(YII_PATH . '/yii.php')) {
return null;
}
require_once YII_PATH . '/yii.php';
spl_autoload_register(array('YiiBase', 'autoload'));
if (\Yii::app() === null) {
$config = (require_once dirname(__FILE__) . '/../config/console.php');
$staticConfig = (require_once dirname(__FILE__) . '/../config/static_config.php');
require_once dirname(__FILE__) . '/../merge.php';
$mergedConfig = array_merge_config($staticConfig, $config);
if ($mergedConfig) {
$app = \Yii::createConsoleApplication($mergedConfig);
} else {
throw new \Exception("File from CONSOLE_CONFIG not found");
}
} else {
$app = \Yii::app();
}
return $app;
}
示例11: getYiiApplication
/**
* Creates console application, if Yii is available
*/
private static function getYiiApplication()
{
if (!is_file(Config::value('yii.path') . '/yii.php')) {
// nothing yet installed, return
return null;
}
require_once Config::value('yii.path') . '/yii.php';
spl_autoload_register(array('YiiBase', 'autoload'));
if (\Yii::app() === null) {
if (!Config::value('envlock')) {
$env = Console::prompt('Please, enter your environment -ie. "dev | prod | stage": ', array('default' => 'dev'));
Initializer::buildEnvironmentFiles($env);
} else {
Console::output("\n%Benv.lock%n file found. No environment request required.\n");
Console::output("Note: if you wish to re-do enviroment setting merging, please remove the %Benv.lock%n file " . "from the Yiinitializr %Bconfig%n folder.");
}
Initializer::createRuntimeFolders();
Initializer::createRuntimeFolders('assets');
if (is_file(Config::value('yiinitializr.config.console'))) {
$app = \Yii::createConsoleApplication(Config::value('yiinitializr.config.console'));
} else {
throw new \Exception("'yiinitializr.config.console' setting not found");
}
} else {
$app = \Yii::app();
}
return $app;
}
示例12: sys_get_temp_dir
<?php
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii/framework/yii.php';
$basePath = sys_get_temp_dir() . '/yii-sass';
if (!is_dir($basePath)) {
if (!mkdir($basePath)) {
throw new Exception('Can not create directory: ' . $basePath);
}
}
Yii::createConsoleApplication(array('basePath' => $basePath));
示例13: ReflectionClass
<?php
echo __FILE__ . ' loaded.' . "\n\n";
$vendordir = __DIR__ . DIRECTORY_SEPARATOR . 'vendor';
require $vendordir . DIRECTORY_SEPARATOR . 'autoload.php';
// workaround to not have yii's autoloader fail when phpunit tries to load
// Php_Invoker.php which is not provided.
Yii::$enableIncludePath = false;
$rclass = new ReflectionClass('YiiBase');
$rprop = $rclass->getProperty('_includePaths');
$rprop->setAccessible(true);
$rprop->setValue(null, array());
Yii::createConsoleApplication(array('basePath' => __DIR__));
示例14: dirname
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
$yiic = (require dirname(__FILE__) . '/../vendor/yiisoft/yii/framework/yii.php');
$config = (require dirname(__FILE__) . '/config/console.php');
$configManager = new yupe\components\ConfigManager();
$configManager->sentEnv(\yupe\components\ConfigManager::ENV_CONSOLE);
$app = \Yii::createConsoleApplication($configManager->merge($config));
$app->commandRunner->addCommands(YII_PATH . '/cli/commands');
$app->run();
示例15: defined
<?php
/**
* Yii command line script file.
*
* This script is meant to be run on command line to execute
* one of the pre-defined console commands.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fix for fcgi
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('YII_DEBUG') or define('YII_DEBUG', true);
require_once $env->yiiPath;
$env->setAlias();
if (isset($config)) {
$app = Yii::createConsoleApplication($config);
$app->commandRunner->addCommands(YII_PATH . '/cli/commands');
} else {
$app = Yii::createConsoleApplication(array('basePath' => dirname(__FILE__) . '/cli'));
}
$env = @getenv('YII_CONSOLE_COMMANDS');
if (!empty($env)) {
$app->commandRunner->addCommands($env);
}
$app->run();