/** * 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'); }
/** * 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); } }
/** * 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'); }
/** * 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)); } }
/** * 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)); } }
/** * 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]; }
/** * Create an instance of a given classname. * * The config is ignore on susequent requests for the same object * name. To reconfigure an existing object, remove() it and re-get(). * * @param string $class The class to build. * @param array $config The constructor configs to pass to the object. * @return mixed */ public static function get($class, array $config = null) { if (!isset(static::$_instances[$class])) { $className = App::className($class, 'Lib', ''); static::$_instances[$class] = new $className($config); } return static::$_instances[$class]; }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * Resolve a filter class name. * * Part of the template method for Cake\Core\ObjectRegistry::load() * * @param string $class Partial class name to resolve. * @return string|false Either the correct class name or false. */ protected function _resolveClassName($class) { $result = App::className($class, 'Model/Filter', 'Filter'); if ($result || strpos($class, '.') !== false) { return $result; } return App::className('PlumSearch.' . $class, 'Model/Filter', 'Filter'); }
/** * 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(); }
/** * {@inheritDoc} * * @param array $config Configuration * @return void */ public function initialize(array $config) { $this->alias('Permissions'); $this->table('aros_acos'); $this->belongsTo('Aros', ['className' => App::className('Acl.ArosTable', 'Model/Table')]); $this->belongsTo('Acos', ['className' => App::className('Acl.AcosTable', 'Model/Table')]); $this->Aro = $this->Aros->target(); $this->Aco = $this->Acos->target(); }
/** * Create an instance of a filter. * * @param string $name The name of the filter to build. * @param array $options Constructor arguments/options for the filter. * @return \Cake\Routing\DispatcherFilter * @throws \Cake\Routing\Exception\MissingDispatcherFilterException When filters cannot be found. */ protected static function _createFilter($name, $options) { $className = App::className($name, 'Routing/Filter', 'Filter'); if (!$className) { $msg = sprintf('Cannot locate dispatcher filter named "%s".', $name); throw new MissingDispatcherFilterException($msg); } return new $className($options); }
/** * Create a single filter * * @param string $name The name of the filter to build. * @param array $config The configuration for the filter. * @return \MiniAsset\Filter\FilterInterface */ protected function buildFilter($name, $config) { $className = App::className($name, 'Filter'); if (!class_exists($className)) { $className = App::className('AssetCompress.' . $name, 'Filter'); } $className = $className ?: $name; return parent::buildFilter($className, $config); }
/** * {@inheritDoc} * * @param array $config Config * @return void */ public function initialize(array $config) { parent::initialize($config); $this->alias('Aros'); $this->table('aros'); $this->addBehavior('Tree', ['type' => 'nested']); $this->belongsToMany('Acos', ['through' => App::className('Acl.PermissionsTable', 'Model/Table'), 'className' => App::className('Acl.AcosTable', 'Model/Table')]); $this->hasMany('AroChildren', ['className' => App::className('Acl.ArosTable', 'Model/Table'), 'foreignKey' => 'parent_id']); $this->entityClass('Acl.Aro', 'Model/Entity'); }
/** * Constructor * */ public function __construct() { $config = []; if (!TableRegistry::exists('Permissions')) { $config = ['className' => App::className('Acl.PermissionsTable', 'Model/Table')]; } $this->Permission = TableRegistry::get('Permissions', $config); $this->Aro = $this->Permission->Aros->target(); $this->Aco = $this->Permission->Acos->target(); }
/** * Return namespace of Entity. * * @param $name * @return bool|string */ public function entity_namespace($name) { $class = ''; $class .= $this->plugin ? $this->plugin . '' : ''; $class .= Inflector::singularize($name); $namespace = App::className($class, 'Model/Entity'); if (!$namespace) { $namespace = 'array'; } return $namespace; }
/** * Default Constructor * * ### Settings: * * - `engine` Class name to use to replace Cake\I18n\Number functionality * The class needs to be placed in the `Utility` directory. * * @param \Cake\View\View $View The View this helper is being attached to. * @param array $config Configuration settings for the helper * @throws \Cake\Core\Exception\Exception When the engine class could not be found. */ public function __construct(View $View, array $config = []) { parent::__construct($View, $config); $config = $this->_config; $engineClass = App::className($config['engine'], 'Utility'); if ($engineClass) { $this->_engine = new $engineClass($config); } else { throw new Exception(sprintf('Class for %s could not be found', $config['engine'])); } }
/** * Returns a mailer instance. * * @param string $name Mailer's name. * @param \Cake\Mailer\Email|null $email Email instance. * @return \Cake\Mailer\Mailer * @throws \Cake\Mailer\Exception\MissingMailerException if undefined mailer class. */ public function getMailer($name, Email $email = null) { if ($email === null) { $email = new Email(); } $className = App::className($name, 'Mailer', 'Mailer'); if (empty($className)) { throw new MissingMailerException(compact('name')); } return new $className($email); }
/** * Returns a notifier instance. * * @param string $name Notifier's name. * @param \CvoTechnologies\Notifier\Notification|null $notification Notification instance. * @return \CvoTechnologies\Notifier\Notification * @throws \CvoTechnologies\Notifier\Exception\MissingNotifierException if undefined notifier class. */ public function getNotifier($name, Notification $notification = null) { if ($notification === null) { $notification = new Notification(); } $className = App::className($name, 'Notifier', 'Notifier'); if (empty($className)) { throw new MissingNotifierException(compact('name')); } return new $className($notification); }
/** * Validates certain custom configuration values. * * @param array $config Raw custom configuration. * @return array * @throws \Muffin\Webservice\Exception\MissingConnectionException If the connection does not exist. * @throws \Muffin\Webservice\Exception\MissingDriverException If the driver does not exist. */ protected function _normalizeConfig($config) { if (empty($config['driver'])) { if (empty($config['service'])) { throw new MissingConnectionException(['name' => $config['name']]); } if (!($config['driver'] = App::className($config['service'], 'Webservice/Driver'))) { throw new MissingDriverException(['driver' => $config['driver']]); } } return $config; }
/** * Get a renderer instance * * @param \Exception $exception The exception being rendered. * @return \Cake\Error\BaseErrorHandler The exception renderer. */ protected function getRenderer($exception) { if (is_string($this->renderer)) { $class = App::className($this->renderer, 'Error'); if (!$class) { throw new \Exception("The '{$this->renderer}' renderer class could not be found."); } return new $class($exception); } $factory = $this->renderer; return $factory($exception); }
/** * Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')` * * @param ComponentRegistry $collection A ComponentRegistry * @param array $config Array of configuration settings * @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('Acl.' . $name, 'Adapter'); if (!$className) { throw new Error\Exception(sprintf('Could not find %s.', $name)); } } $this->adapter($className); }
/** * Builds the path builder for given interface. * * @param string $name * @param array $options * @return \Burzum\FileStorage\Storage\PathBuilder\PathBuilderInterface */ public function createPathBuilder($name, array $options = []) { $className = App::className($name, 'Storage/PathBuilder', 'PathBuilder'); if (!class_exists($className)) { $className = App::className('Burzum/FileStorage.' . $name, 'Storage/PathBuilder', 'PathBuilder'); } if (!class_exists($className)) { throw new RuntimeException(sprintf('Could not find path builder "%s"!', $name)); } $pathBuilder = new $className($options); if (!$pathBuilder instanceof PathBuilderInterface) { throw new RuntimeException(sprintf('Path builder class "%s" does not implement the PathBuilderInterface interface!', $name)); } return $pathBuilder; }
/** * @param \Cake\Controller\ComponentRegistry $registry Component registry * @param array $config Config array */ public function __construct(ComponentRegistry $registry, $config) { parent::__construct($registry, $config); if ($this->config('server')) { $this->Server = $this->config('server'); return; } $serverConfig = $this->config('resourceServer'); $serverClassName = App::className($serverConfig['className']); if (!$serverClassName) { throw new Exception('ResourceServer class was not found.'); } $server = new $serverClassName($this->_getStorage('session'), $this->_getStorage('accessToken'), $this->_getStorage('client'), $this->_getStorage('scope')); $this->Server = $server; }
/** * Constructs the view class instance based on object properties. * * @param string $viewClass Optional namespaced class name of the View class to instantiate. * @return \Cake\View\View * @throws \Cake\View\Exception\MissingViewException If view class was not found. */ public function createView($viewClass = null) { if ($viewClass === null) { $viewClass = $this->viewClass; } if ($viewClass === 'View') { $className = App::className($viewClass, 'View'); } else { $className = App::className($viewClass, 'View', 'View'); } if (!$className) { throw new Exception\MissingViewException([$viewClass]); } $viewOptions = array_intersect_key(get_object_vars($this), array_flip($this->_validViewOptions)); return new $className($this->request, $this->response, $this->eventManager(), $viewOptions); }
/** * Call this method in order to register an entity action registry implementation with this EntityActionManager. * @param mixed $registry * Either a string providing the name of a class implementing the IEntityActionRegistry interface, or an instance of a class * implementing IEntityActionRegistry. * @throws MissingEntityActionRegistryException * Thrown, if the provided registry neither is the name of a suitable class nor a suitable IEntityActionRegistry object. */ public static function registry($registry) { if (is_string($registry)) { $className = App::className($registry, 'EntityAction'); if (!$className) { throw new MissingEntityActionRegistryException(sprintf('Cannot locate entity action registry named "%s".', $registry)); } static::$entityActionRegistry = new $className(); } else { if (is_a($registry, 'EntityActions\\Manager\\IEntityActionRegistry')) { static::$entityActionRegistry = $registry; } else { $registryString = is_object($registry) ? get_class($registry) : (string) $registry; throw new MissingEntityActionRegistryException(sprintf('"%s" neither implements IEntityActionRegistry nor is it a valid entity action registry class name.', $registryString)); } } }
/** * Resolve middleware name to callable. * * @param int $index The index to fetch. * @return callable|null Either the callable middleware or null * if the index is undefined. */ protected function resolve($index) { if (!isset($this->queue[$index])) { return null; } if (is_string($this->queue[$index])) { $class = $this->queue[$index]; $className = App::className($class, 'Middleware', 'Middleware'); if (!$className || !class_exists($className)) { throw new RuntimeException(sprintf('Middleware "%s" was not found.', $class)); } $callable = new $className(); } else { $callable = $this->queue[$index]; } return $this->callables[$index] = $callable; }
/** * Ensures the tables for the given fixtures exist in the schema. * * If the tables do not exist, they will be created on the current model's connection. * * @param array $fixtures The fixture names to check and/or insert. * @return void * @throws \RuntimeException When fixtures are missing/unknown/fail. */ public function ensureTables(array $fixtures) { $connection = $this->connection(); $schema = $connection->schemaCollection(); $existing = $schema->listTables(); foreach ($fixtures as $name) { $class = App::className($name, 'Test/Fixture', 'Fixture'); if ($class === false) { throw new \RuntimeException("Unknown fixture '{$name}'."); } $fixture = new $class(); $table = $fixture->table; if (in_array($table, $existing)) { continue; } $fixture->create($connection); } }