本文整理汇总了PHP中Cake\Core\App类的典型用法代码示例。如果您正苦于以下问题:PHP App类的具体用法?PHP App怎么用?PHP App使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了App类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: startup
/**
* Override startup of the Shell
*
* @return void
*/
public function startup()
{
parent::startup();
if (isset($this->params['connection'])) {
$this->connection = $this->params['connection'];
}
$class = Configure::read('Acl.classname');
$className = App::classname('Acl.' . $class, 'Adapter');
if ($class !== 'DbAcl' && !is_subclass_of($className, 'Acl\\Adapter\\DbAcl')) {
$out = "--------------------------------------------------\n";
$out .= __d('cake_acl', 'Error: Your current CakePHP configuration is set to an ACL implementation other than DB.') . "\n";
$out .= __d('cake_acl', 'Please change your core config to reflect your decision to use DbAcl before attempting to use this script') . "\n";
$out .= "--------------------------------------------------\n";
$out .= __d('cake_acl', 'Current ACL Classname: %s', $class) . "\n";
$out .= "--------------------------------------------------\n";
$this->err($out);
return $this->_stop();
}
if ($this->command) {
if (Configure::check('Datasource') === null) {
$this->out(__d('cake_acl', 'Your database configuration was not found. Take a moment to create one.'));
$this->args = null;
return $this->DbConfig->execute();
}
if (!in_array($this->command, ['initdb'])) {
$registry = new ComponentRegistry();
$this->Acl = new AclComponent($registry);
$controller = new Controller();
}
}
}
开发者ID:ceeram,项目名称:acl,代码行数:36,代码来源:AclShell.php
示例2: _getController
/**
* Gets controller to use, either plugin or application controller.
*
* @param \Cake\Network\Request $request Request object
* @param \Cake\Network\Response $response Response for the controller.
* @return \Cake\Controller\Controller|false Object if loaded, boolean false otherwise.
*/
protected function _getController($request, $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (!empty($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if (!empty($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (!empty($request->params['prefix'])) {
$namespace .= '/' . $request->params['prefix'];
}
$firstChar = substr($controller, 0, 1);
if (strpos($controller, '\\') !== false || strpos($controller, '.') !== false || $firstChar === strtolower($firstChar)) {
return false;
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return false;
}
$reflection = new ReflectionClass($className);
if ($reflection->isAbstract() || $reflection->isInterface()) {
return false;
}
return $reflection->newInstance($request, $response, $controller);
}
开发者ID:ChrisDBrown,项目名称:cakephp,代码行数:37,代码来源:ControllerFactoryFilter.php
示例3: _findTemplates
/**
* Find the paths to all the installed shell templates in the app.
*
* Bake templates are directories under `Template/Bake` path.
* They are listed in this order: app -> plugin -> default
*
* @return array Array of bake templates that are installed.
*/
protected function _findTemplates()
{
$paths = App::path('Template');
$plugins = Plugin::loaded();
foreach ($plugins as $plugin) {
$paths[] = Plugin::classPath($plugin) . 'Template' . DS;
}
$core = current(App::core('Template'));
$Folder = new Folder($core . 'Bake' . DS . 'default');
$contents = $Folder->read();
$templateFolders = $contents[0];
$paths[] = $core;
foreach ($paths as $i => $path) {
$paths[$i] = rtrim($path, DS) . DS;
}
$this->_io->verbose('Found the following bake templates:');
$templates = [];
foreach ($paths as $path) {
$Folder = new Folder($path . 'Bake', false);
$contents = $Folder->read();
$subDirs = $contents[0];
foreach ($subDirs as $dir) {
$Folder = new Folder($path . 'Bake' . DS . $dir);
$contents = $Folder->read();
$subDirs = $contents[0];
if (array_intersect($contents[0], $templateFolders)) {
$templateDir = $path . 'Bake' . DS . $dir . DS;
$templates[$dir] = $templateDir;
$this->_io->verbose(sprintf("- %s -> %s", $dir, $templateDir));
}
}
}
return $templates;
}
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:42,代码来源:TemplateTask.php
示例4: install
/**
* Installing plugin
* @param null $zipPath
* @return array|bool
* @throws CakeException
*/
public function install($zipPath = null)
{
if (!file_exists($zipPath)) {
throw new Exception(__d('spider', 'Invalid plugin file path'));
}
$pluginInfo = $this->getPluginMeta($zipPath);
$pluginHomeDir = App::path('Plugin');
$pluginHomeDir = reset($pluginHomeDir);
$pluginPath = $pluginHomeDir . $pluginInfo->name . DS;
if (is_dir($pluginPath)) {
throw new Exception(__d('spider', 'Plugin already exists'));
}
$Zip = new \ZipArchive();
if ($Zip->open($zipPath) === true) {
new Folder($pluginPath, true);
$Zip->extractTo($pluginPath);
if (!empty($pluginInfo->rootPath)) {
$old = $pluginPath . $pluginInfo->rootPath;
$new = $pluginPath;
$Folder = new Folder($old);
$Folder->move($new);
}
$Zip->close();
return (array) $pluginInfo;
} else {
throw new CakeException(__d('spider', 'Failed to extract plugin'));
}
return false;
}
开发者ID:mohammadsaleh,项目名称:spider,代码行数:35,代码来源:PluginInstaller.php
示例5: _getController
/**
* Get controller to use, either plugin controller or application controller
*
* @param \Cake\Network\Request $request Request object
* @param \Cake\Network\Response $response Response for the controller.
* @return mixed name of controller if not loaded, or object if loaded
*/
protected function _getController($request, $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (!empty($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if (!empty($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (!empty($request->params['prefix'])) {
$prefixes = array_map('Cake\\Utility\\Inflector::camelize', explode('/', $request->params['prefix']));
$namespace .= '/' . implode('/', $prefixes);
}
if (strpos($controller, '\\') !== false || strpos($controller, '.') !== false) {
return false;
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return false;
}
$reflection = new ReflectionClass($className);
if ($reflection->isAbstract() || $reflection->isInterface()) {
return false;
}
return $reflection->newInstance($request, $response, $controller);
}
开发者ID:rederlo,项目名称:cakephp,代码行数:37,代码来源:ControllerFactoryFilter.php
示例6: _getController
/**
* Get controller to use, either plugin controller or application controller
*
* @param \Cake\Network\Request $request Request object
* @param \Cake\Network\Response $response Response for the controller.
* @return mixed name of controller if not loaded, or object if loaded
*/
protected function _getController($request, $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (!empty($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if (!empty($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (!empty($request->params['prefix'])) {
$namespace .= '/' . Inflector::camelize($request->params['prefix']);
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return false;
}
$reflection = new \ReflectionClass($className);
if ($reflection->isAbstract() || $reflection->isInterface()) {
return false;
}
return $reflection->newInstance($request, $response);
}
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:33,代码来源:ControllerFactoryFilter.php
示例7: create
/**
* Create a controller for a given request/response
*
* @param \Cake\Network\Request $request The request to build a controller for.
* @param \Cake\Network\Response $response The response to use.
* @return \Cake\Controller\Controller
*/
public function create(Request $request, Response $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (isset($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if (isset($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (isset($request->params['prefix'])) {
if (strpos($request->params['prefix'], '/') === false) {
$namespace .= '/' . Inflector::camelize($request->params['prefix']);
} else {
$prefixes = array_map('Cake\\Utility\\Inflector::camelize', explode('/', $request->params['prefix']));
$namespace .= '/' . implode('/', $prefixes);
}
}
$firstChar = substr($controller, 0, 1);
if (strpos($controller, '\\') !== false || strpos($controller, '.') !== false || $firstChar === strtolower($firstChar)) {
return $this->missingController($request);
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return $this->missingController($request);
}
$reflection = new ReflectionClass($className);
if ($reflection->isAbstract() || $reflection->isInterface()) {
return $this->missingController($request);
}
return $reflection->newInstance($request, $response, $controller);
}
开发者ID:markstory,项目名称:cakephp-spekkoek,代码行数:42,代码来源:ControllerFactory.php
示例8: initialize
/**
* Overwrite shell initialize to dynamically load all Queue Related Tasks.
*
* @return void
*/
public function initialize()
{
$plugins = Plugin::loaded();
foreach ($plugins as $plugin) {
$pluginPaths = App::path('Shell/Task', $plugin);
foreach ($pluginPaths as $pluginPath) {
$Folder = new Folder($pluginPath);
$res = $Folder->find('Queue.+Task\\.php');
foreach ($res as &$r) {
$r = $plugin . '.' . basename($r, 'Task.php');
}
$this->tasks = array_merge($this->tasks, $res);
}
}
$paths = App::path('Shell/Task');
foreach ($paths as $path) {
$Folder = new Folder($path);
$res = array_merge($this->tasks, $Folder->find('Queue.+\\.php'));
foreach ($res as &$r) {
$r = basename($r, 'Task.php');
}
$this->tasks = $res;
}
parent::initialize();
$this->QueuedTasks->initConfig();
}
开发者ID:repher,项目名称:cakephp-queue,代码行数:31,代码来源:QueueShell.php
示例9: __construct
/**
* Sets up the configuration for the model, and loads ACL models if they haven't been already
*
* @param Table $model Table instance being attached
* @param array $config Configuration
* @return void
*/
public function __construct(Table $model, array $config = [])
{
$this->_table = $model;
if (isset($config[0])) {
$config['type'] = $config[0];
unset($config[0]);
}
if (isset($config['type'])) {
$config['type'] = strtolower($config['type']);
}
parent::__construct($model, $config);
$types = $this->_typeMaps[$this->config()['type']];
if (!is_array($types)) {
$types = [$types];
}
foreach ($types as $type) {
$alias = Inflector::pluralize($type);
$className = App::className($alias . 'Table', 'Model/Table');
if ($className == false) {
$className = App::className('Acl.' . $alias . 'Table', 'Model/Table');
}
$config = [];
if (!TableRegistry::exists($alias)) {
$config = ['className' => $className];
}
$model->hasMany($type, ['targetTable' => TableRegistry::get($alias, $config)]);
}
if (!method_exists($model->entityClass(), 'parentNode')) {
trigger_error(__d('cake_dev', 'Callback {0} not defined in {1}', ['parentNode()', $model->entityClass()]), E_USER_WARNING);
}
}
开发者ID:cakephp,项目名称:acl,代码行数:38,代码来源:AclBehavior.php
示例10: _resolveClassName
/**
* Resolve a driver classname.
*
* Part of the template method for Cake\Core\ObjectRegistry::load()
*
* @param string $class Partial classname to resolve.
* @return string|false Either the correct classname or false.
*/
protected function _resolveClassName($class)
{
if (is_object($class)) {
return $class;
}
return App::className($class, 'Datasource');
}
开发者ID:CakeDC,项目名称:cakephp,代码行数:15,代码来源:ConnectionRegistry.php
示例11: cell
/**
* Renders the given cell.
*
* Example:
*
* ```
* // Taxonomy\View\Cell\TagCloudCell::smallList()
* $cell = $this->cell('Taxonomy.TagCloud::smallList', ['limit' => 10]);
*
* // App\View\Cell\TagCloudCell::smallList()
* $cell = $this->cell('TagCloud::smallList', ['limit' => 10]);
* ```
*
* The `display` action will be used by default when no action is provided:
*
* ```
* // Taxonomy\View\Cell\TagCloudCell::display()
* $cell = $this->cell('Taxonomy.TagCloud');
* ```
*
* Cells are not rendered until they are echoed.
*
* @param string $cell You must indicate cell name, and optionally a cell action. e.g.: `TagCloud::smallList`
* will invoke `View\Cell\TagCloudCell::smallList()`, `display` action will be invoked by default when none is provided.
* @param array $data Additional arguments for cell method. e.g.:
* `cell('TagCloud::smallList', ['a1' => 'v1', 'a2' => 'v2'])` maps to `View\Cell\TagCloud::smallList(v1, v2)`
* @param array $options Options for Cell's constructor
* @return \Cake\View\Cell The cell instance
* @throws \Cake\View\Exception\MissingCellException If Cell class was not found.
* @throws \BadMethodCallException If Cell class does not specified cell action.
*/
public function cell($cell, array $data = [], array $options = [])
{
$parts = explode('::', $cell);
if (count($parts) === 2) {
list($pluginAndCell, $action) = [$parts[0], $parts[1]];
} else {
list($pluginAndCell, $action) = [$parts[0], 'display'];
}
list($plugin) = pluginSplit($pluginAndCell);
$className = App::className($pluginAndCell, 'View/Cell', 'Cell');
if (!$className) {
throw new Exception\MissingCellException(['className' => $pluginAndCell . 'Cell']);
}
$cell = $this->_createCell($className, $action, $plugin, $options);
if (!empty($data)) {
$data = array_values($data);
}
try {
$reflect = new ReflectionMethod($cell, $action);
$reflect->invokeArgs($cell, $data);
return $cell;
} catch (ReflectionException $e) {
throw new BadMethodCallException(sprintf('Class %s does not have a "%s" method.', $className, $action));
}
}
开发者ID:rederlo,项目名称:cakephp,代码行数:56,代码来源:CellTrait.php
示例12: gizmo
/**
* Renders the given gizmo.
*
* Example:
*
* {{{
* // Taxonomy\View\Gizmo\TagCloudGizmo::smallList()
* $gizmo = $this->gizmo('Taxonomy.TagCloud::smallList', ['limit' => 10]);
*
* // App\View\Gizmo\TagCloudGizmo::smallList()
* $gizmo = $this->gizmo('TagCloud::smallList', ['limit' => 10]);
* }}}
*
* The `display` action will be used by default when no action is provided:
*
* {{{
* // Taxonomy\View\Gizmo\TagCloudGizmo::display()
* $gizmo = $this->gizmo('Taxonomy.TagCloud');
* }}}
*
* Gizmos are not rendered until they are echoed.
*
* @param string $gizmo You must indicate gizmo name, and optionally a gizmo action. e.g.: `TagCloud::smallList`
* will invoke `View\Gizmo\TagCloudGizmo::smallList()`, `display` action will be invoked by default when none is provided.
* @param array $data Additional arguments for gizmo method. e.g.:
* `gizmo('TagCloud::smallList', ['a1' => 'v1', 'a2' => 'v2'])` maps to `View\Gizmo\TagCloud::smallList(v1, v2)`
* @param array $options Options for Gizmo's constructor
* @return \Cake\View\Gizmo The gizmo instance
* @throws \Cake\View\Exception\MissingGizmoException If Gizmo class was not found.
* @throws \BadMethodCallException If Gizmo class does not specified gizmo action.
*/
public function gizmo($gizmo, array $data = [], array $options = [])
{
$parts = explode('::', $gizmo);
if (count($parts) === 2) {
list($pluginAndGizmo, $action) = [$parts[0], $parts[1]];
} else {
list($pluginAndGizmo, $action) = [$parts[0], 'display'];
}
list($plugin, $gizmoName) = pluginSplit($pluginAndGizmo);
$className = App::className($pluginAndGizmo, 'View/Gizmo', 'Gizmo');
if (!$className) {
throw new Exception\MissingGizmoException(array('className' => $pluginAndGizmo . 'Gizmo'));
}
$gizmo = $this->_createGizmo($className, $action, $plugin, $options);
if (!empty($data)) {
$data = array_values($data);
}
try {
$reflect = new \ReflectionMethod($gizmo, $action);
$reflect->invokeArgs($gizmo, $data);
return $gizmo;
} catch (\ReflectionException $e) {
throw new \BadMethodCallException(sprintf('Class %s does not have a "%s" method.', $className, $action));
}
}
开发者ID:splicephp,项目名称:gizmo,代码行数:56,代码来源:GizmoTrait.php
示例13: _getController
/**
* Get controller to use, either plugin controller or application controller
*
* @param \Cake\Network\Request $request Request object
* @param \Cake\Network\Response $response Response for the controller.
* @return mixed name of controller if not loaded, or object if loaded
*/
protected function _getController($request, $response)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if (!empty($request->params['plugin'])) {
$pluginPath = $request->params['plugin'] . '.';
}
if ($pluginPath) {
return parent::_getController($request, $response);
}
if (!empty($request->params['controller'])) {
$controller = $request->params['controller'];
}
if (!empty($request->params['prefix'])) {
$namespace .= '/' . Inflector::camelize($request->params['prefix']);
}
$className = false;
if ($pluginPath . $controller) {
$className = App::classname($pluginPath . $controller, $namespace, 'Controller');
}
if (!$className) {
return false;
}
$instance = PipingBag::get($className);
if (method_exists($instance, 'viewBuilder')) {
$instance->viewBuilder();
} else {
$instance->viewPath = null;
}
$instance->name = $controller;
$instance->setRequest($request);
$instance->response = $response;
return $instance;
}
开发者ID:lorenzo,项目名称:piping-bag,代码行数:41,代码来源:ControllerFactoryFilter.php
示例14: get
/**
* Get/Create an instance from the registry.
*
* When getting an instance, if it does not already exist,
* a new instance will be created using the provide alias, and options.
*
* @param string $alias The name of the alias to get.
* @param array $options Configuration options for the type constructor.
* @return \Cake\ElasticSearch\Type
*/
public static function get($alias, array $options = [])
{
if (isset(static::$instances[$alias])) {
if (!empty($options) && static::$options[$alias] !== $options) {
throw new RuntimeException(sprintf('You cannot configure "%s", it already exists in the registry.', $alias));
}
return static::$instances[$alias];
}
static::$options[$alias] = $options;
list(, $classAlias) = pluginSplit($alias);
$options = $options + ['name' => Inflector::underscore($classAlias)];
if (empty($options['className'])) {
$options['className'] = Inflector::camelize($alias);
}
$className = App::className($options['className'], 'Model/Type', 'Type');
if ($className) {
$options['className'] = $className;
} else {
if (!isset($options['name']) && strpos($options['className'], '\\') === false) {
list(, $name) = pluginSplit($options['className']);
$options['name'] = Inflector::underscore($name);
}
$options['className'] = 'Cake\\ElasticSearch\\Type';
}
if (empty($options['connection'])) {
$connectionName = $options['className']::defaultConnectionName();
$options['connection'] = ConnectionManager::get($connectionName);
}
static::$instances[$alias] = new $options['className']($options);
return static::$instances[$alias];
}
开发者ID:jeffersongoncalves,项目名称:elastic-search,代码行数:41,代码来源:TypeRegistry.php
示例15: _resolveClassName
/**
* Resolve a cache engine classname.
*
* Part of the template method for Cake\Core\ObjectRegistry::load()
*
* @param string $class Partial classname to resolve.
* @return string|false Either the correct classname or false.
*/
protected function _resolveClassName($class)
{
if (is_object($class)) {
return $class;
}
return App::className($class, 'Cache/Engine', 'Engine');
}
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:15,代码来源:CacheRegistry.php
示例16: _resolveClassName
/**
* Resolve a behavior classname.
*
* Part of the template method for Cake\Core\ObjectRegistry::load()
*
* @param string $class Partial classname to resolve.
* @return string|false Either the correct classname or false.
*/
protected function _resolveClassName($class)
{
$result = App::className($class, 'Model/Behavior', 'Behavior');
if (!$result) {
$result = App::className($class, 'ORM/Behavior', 'Behavior');
}
return $result;
}
开发者ID:rederlo,项目名称:cakephp,代码行数:16,代码来源:BehaviorRegistry.php
示例17: getTransformer
/**
* Generates instance of the Transformer.
*
* The method works with the App::className() method.
* This means that you can call app-related Transformers like `Books`.
* Plugin-related Transformers can be called like `Plugin.Books`
*
* @param $className
* @return TransformerAbstract
* @throws MissingTransformerException
*/
public function getTransformer($className)
{
$transformer = App::className(Inflector::classify($className), 'Transformer', 'Transformer');
if ($transformer === false) {
throw new MissingTransformerException(['transformer' => $className]);
}
return new $transformer();
}
开发者ID:cakeplugins,项目名称:api,代码行数:19,代码来源:TransformerAwareTrait.php
示例18: generateSender
/**
* generate Encount Sender
*
* @access private
* @author sakuragawa
*/
private function generateSender($name)
{
$class = App::className($name, 'Sender');
if (!class_exists($class)) {
throw new InvalidArgumentException(sprintf('Encount sender "%s" was not found.', $class));
}
return new $class();
}
开发者ID:fusic,项目名称:encount,代码行数:14,代码来源:EncountErrorHandler.php
示例19: _resolveClassName
/**
* Resolve a storage class name.
*
* @param string $class Partial class name to resolve.
* @return string The resolved class name.
* @throws \Cake\Core\Exception\Exception
*/
protected function _resolveClassName($class)
{
$className = App::className($class, 'Model/Storage', 'Storage');
if (!$className) {
throw new Exception(sprintf('Storage class "%s" was not found.', $class));
}
return $className;
}
开发者ID:laughingpain,项目名称:oauth-server,代码行数:15,代码来源:GetStorageTrait.php
示例20: plugin
/**
* Return all templates for a given plugin.
*
* @param string $plugin The plugin to find all templates for.
*
* @return mixed
*/
public static function plugin($plugin)
{
$templates = [];
foreach (App::path('Template', $plugin) as $path) {
$templates = array_merge($templates, static::iteratePath($path));
}
return $templates;
}
开发者ID:luisfredgs,项目名称:TwigView,代码行数:15,代码来源:Scanner.php
注:本文中的Cake\Core\App类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论