本文整理汇总了PHP中Cake\Core\App::classname方法的典型用法代码示例。如果您正苦于以下问题:PHP App::classname方法的具体用法?PHP App::classname怎么用?PHP App::classname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Core\App
的用法示例。
在下文中一共展示了App::classname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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');
if (strpos($class, '\\') === false && strpos($class, '.') === false) {
$className = App::classname('Acl.' . $class, 'Adapter');
} else {
$className = App::classname($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: {0}', [$class]) . "\n";
$out .= "--------------------------------------------------\n";
$this->err($out);
$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;
$this->DbConfig->execute();
return;
}
try {
TableRegistry::get('Aros')->schema();
TableRegistry::remove('Aros');
} catch (\Cake\Database\Exception $e) {
$this->out(__d('cake_acl', 'Acl database tables not found. To create them, run:'));
$this->out();
$this->out(' bin/cake Migrations.migrations migrate -p Acl');
$this->out();
$this->_stop();
return;
}
$registry = new ComponentRegistry();
$this->Acl = new AclComponent($registry);
}
}
示例2: 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);
}
示例3: _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);
}
示例4: _resolveClassName
/**
* Resolve a logger classname.
*
* Part of the template method for Cake\Utility\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, 'Log/Engine', 'Log');
}
示例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);
}
示例6: _resolveClassName
/**
* Resolve a driver classname.
*
* Part of the template method for Cake\Utility\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');
}
示例7: 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();
}
}
}
示例8: _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;
}
示例9: _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);
}
示例10: __construct
/**
* Default Constructor
*
* ### Settings:
*
* - `engine` Class name to use to replace Cake\Utility\Number functionality
* The class needs to be placed in the `Utility` directory.
*
* @param View $View The View this helper is being attached to.
* @param array $config Configuration settings for the helper
* @throws \Cake\Error\Exception When the engine class could not be found.
*/
public function __construct(View $View, array $config = array())
{
parent::__construct($View, $config);
$config = $this->_config;
$engineClass = App::classname($config['engine'], 'Utility');
if ($engineClass) {
$this->_engine = new $engineClass($config);
} else {
throw new Error\Exception(sprintf('Class for %s could not be found', $config['engine']));
}
}
示例11: createView
/**
* Constructs the view class instance based on object properties.
*
* @param string $viewClass Optional namespaced class name of the View class to instantiate.
* @return View
*/
public function createView($viewClass = null)
{
if ($viewClass === null) {
$viewClass = $this->viewClass;
if ($this->viewClass !== 'View') {
list($plugin, $viewClass) = pluginSplit($viewClass, true);
$viewClass = App::classname($viewClass, 'View', 'View');
}
}
$viewOptions = array_intersect_key(get_object_vars($this), array_flip($this->_validViewOptions));
return new $viewClass($this->request, $this->response, $this->getEventManager(), $viewOptions);
}
示例12: __construct
/**
* Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')`
*
* @param ComponentRegistry $collection
* @param array $config
* @throws \Cake\Error\Exception when Acl.classname could not be loaded.
*/
public function __construct(ComponentRegistry $collection, array $config = array())
{
parent::__construct($collection, $config);
$classname = $name = Configure::read('Acl.classname');
if (!class_exists($classname)) {
$classname = App::classname($name, 'Controller/Component/Acl');
if (!$classname) {
throw new Error\Exception(sprintf('Could not find %s.', $name));
}
}
$this->adapter($classname);
}
示例13: configure
protected function configure()
{
$this->bind('Cake\\Event\\EventManager');
$this->install(new AssistedModule());
array_map(function ($module) {
if (!is_string($module)) {
return $module;
}
$class = App::classname($module, 'Di/Module');
if (!$class) {
throw new \InvalidArgumentException('Invalid Di module name: ' . $module);
}
$this->install(new $class());
}, $this->configuration);
}
示例14: 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 both 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\Error\MissingCellException If Cell class was not found
*/
public function cell($cell, $data = [], $options = [])
{
$parts = explode('::', $cell);
if (count($parts) == 2) {
list($pluginAndCell, $action) = [$parts[0], $parts[1]];
} else {
list($pluginAndCell, $action) = [$parts[0], 'display'];
}
list($plugin, $cellName) = pluginSplit($pluginAndCell);
$className = App::classname($pluginAndCell, 'View/Cell', 'Cell');
if (!$className) {
throw new Error\MissingCellException(array('className' => $pluginAndCell . 'Cell'));
}
$cellInstance = new $className($this->request, $this->response, $this->getEventManager(), $options);
$cellInstance->template = Inflector::underscore($action);
$cellInstance->plugin = !empty($plugin) ? $plugin : null;
$cellInstance->theme = !empty($this->theme) ? $this->theme : null;
$length = count($data);
if ($length) {
$data = array_values($data);
}
call_user_func_array([$cellInstance, $action], $data);
return $cellInstance;
}
示例15: entityClass
/**
* Returns the class used to hydrate rows for this table or sets
* a new one
*
* @param string $name the name of the class to use
* @throws \RuntimeException when the entity class cannot be found
* @return string
*/
public function entityClass($name = null)
{
if ($name === null && !$this->_documentClass) {
$default = '\\Cake\\ElasticSearch\\Document';
$self = get_called_class();
$parts = explode('\\', $self);
if ($self === __CLASS__ || count($parts) < 3) {
return $this->_documentClass = $default;
}
$alias = Inflector::singularize(substr(array_pop($parts), 0, -4));
$name = implode('\\', array_slice($parts, 0, -1)) . '\\Document\\' . $alias;
if (!class_exists($name)) {
return $this->_documentClass = $default;
}
}
if ($name !== null) {
$class = App::classname($name, 'Model/Document');
$this->_documentClass = $class;
}
if (!$this->_documentClass) {
throw new \RuntimeException(sprintf('Missing document class "%s"', $class));
}
return $this->_documentClass;
}