本文整理匯總了PHP中namespaceSplit函數的典型用法代碼示例。如果您正苦於以下問題:PHP namespaceSplit函數的具體用法?PHP namespaceSplit怎麽用?PHP namespaceSplit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了namespaceSplit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: filterAssociations
/**
* Returns filtered associations for controllers models. HasMany association are filtered if
* already existing in BelongsToMany
*
* @param Table $model The model to build associations for.
* @return array associations
*/
public function filterAssociations(Table $model)
{
$belongsToManyJunctionsAliases = $this->belongsToManyJunctionAliases($model);
$keys = ['BelongsTo', 'HasOne', 'HasMany', 'BelongsToMany'];
$associations = [];
foreach ($keys as $type) {
foreach ($model->associations()->type($type) as $assoc) {
$target = $assoc->target();
$assocName = $assoc->name();
$alias = $target->alias();
//filter existing HasMany
if ($type === 'HasMany' && in_array($alias, $belongsToManyJunctionsAliases)) {
continue;
}
$targetClass = get_class($target);
list(, $className) = namespaceSplit($targetClass);
$navLink = true;
$modelClass = get_class($model);
if ($modelClass !== 'Cake\\ORM\\Table' && $targetClass === $modelClass) {
$navLink = false;
}
$className = preg_replace('/(.*)Table$/', '\\1', $className);
if ($className === '') {
$className = $alias;
}
try {
$associations[$type][$assocName] = ['property' => $assoc->property(), 'variable' => Inflector::variable($assocName), 'primaryKey' => (array) $target->primaryKey(), 'displayField' => $target->displayField(), 'foreignKey' => $assoc->foreignKey(), 'alias' => $alias, 'controller' => $className, 'fields' => $target->schema()->columns(), 'navLink' => $navLink];
} catch (Exception $e) {
// Do nothing it could be a bogus association name.
}
}
}
return $associations;
}
示例2: elementName
/**
* Get the element name for the panel.
*
* @return string
*/
public function elementName()
{
list($ns, $name) = namespaceSplit(get_class($this));
if ($this->plugin) {
return $this->plugin . '.' . Inflector::underscore($name);
}
return Inflector::underscore($name);
}
示例3: _repository
/**
* Gets the repository for this entity
*
* @param EntityInterface $entity
* @return Table
*/
protected function _repository($entity)
{
$source = $entity->source();
if ($source === null) {
list(, $class) = namespaceSplit(get_class($entity));
$source = Inflector::pluralize($class);
}
return TableRegistry::get($source);
}
示例4: method
/**
* Returns the database method name or sets a new one
*
* @param string|null $method the new method name
* @return string
*/
public function method($method = null)
{
if ($method !== null) {
$this->_method = $method;
}
if ($this->_method === null) {
$method = namespaceSplit(get_class($this));
$method = substr(end($method), 0, -6);
$this->_method = Inflector::underscore($method);
}
return $this->_method;
}
示例5: __construct
public function __construct(MacroRegistry $macroRegistry, array $config = [], $name = null)
{
if ($this->name === null && $name === null) {
list(, $name) = namespaceSplit(get_class($this));
$name = substr($name, 0, -5);
}
if ($name !== null) {
$this->name = $name;
}
$this->config($config);
$this->modelFactory('Table', ['Cake\\ORM\\TableRegistry', 'get']);
$modelClass = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
$this->_setModelClass($modelClass);
}
示例6: render
/**
* Renders the response for the exception.
*
* @return Response The response to be sent.
*/
public function render($exception)
{
$exception = $exception instanceof PHP7ErrorException ? $exception->getError() : $exception;
list(, $baseClass) = namespaceSplit(get_class($exception));
if (substr($baseClass, -9) === 'Exception') {
$baseClass = substr($baseClass, 0, -9);
}
$action = (new Text($baseClass))->camelBackize() ?: 'error500';
$class = Core::className('Error', 'Controller', 'Controller');
$controller = new $class();
if (!in_array($action, get_class_methods($controller))) {
$action = "processError";
}
return $controller->callAction($action, ["exception" => $exception, "request" => Router::getInstance()->request()]);
}
示例7: type
/**
* Get an array of associations matching a specific type.
*
* @param string $class The type of associations you want. For example 'BelongsTo'
* @return array An array of Association objects.
*/
public function type($class)
{
$out = array_filter($this->_items, function ($assoc) use($class) {
list($ns, $name) = namespaceSplit(get_class($assoc));
return $class === $name;
});
return array_values($out);
}
示例8: _prepare
/**
* Prepare some additional data from the context.
*
* If the table option was provided to the constructor and it
* was a string, ORM\TableRegistry will be used to get the correct table instance.
*
* If an object is provided as the table option, it will be used as is.
*
* If no table option is provided, the table name will be derived based on
* naming conventions. This inference will work with a number of common objects
* like arrays, Collection objects and ResultSets.
*
* @return void
* @throws \RuntimeException When a table object cannot be located/inferred.
*/
protected function _prepare()
{
$table = $this->_context['table'];
$entity = $this->_context['entity'];
if (empty($table)) {
if (is_array($entity) || $entity instanceof Traversable) {
$entity = (new Collection($entity))->first();
}
$isEntity = $entity instanceof Entity;
if ($isEntity) {
$table = $entity->source();
}
if (!$table && $isEntity && get_class($entity) !== 'Cake\\ORM\\Entity') {
list($ns, $entityClass) = namespaceSplit(get_class($entity));
$table = Inflector::pluralize($entityClass);
}
}
if (is_string($table)) {
$table = TableRegistry::get($table);
}
if (!is_object($table)) {
throw new \RuntimeException('Unable to find table class for current entity');
}
$this->_isCollection = is_array($entity) || $entity instanceof Traversable;
$alias = $this->_rootName = $table->alias();
$this->_tables[$alias] = $table;
}
示例9: __construct
/**
* Constructor.
*
* Sets a number of properties based on conventions if they are empty. To override the
* conventions CakePHP uses you can define properties in your class declaration.
*
* @param \Cake\Network\Request|null $request Request object for this controller. Can be null for testing,
* but expect that features that use the request parameters will not work.
* @param \Cake\Network\Response|null $response Response object for this controller.
* @param string|null $name Override the name useful in testing when using mocks.
* @param \Cake\Event\EventManager|null $eventManager The event manager. Defaults to a new instance.
*/
public function __construct(Request $request = null, Response $response = null, $name = null, $eventManager = null)
{
if ($this->name === null && $name === null) {
list(, $name) = namespaceSplit(get_class($this));
$name = substr($name, 0, -10);
}
if ($name !== null) {
$this->name = $name;
}
if (!$this->viewPath) {
$viewPath = $this->name;
if (isset($request->params['prefix'])) {
$prefixes = array_map('Cake\\Utility\\Inflector::camelize', explode('/', $request->params['prefix']));
$viewPath = implode(DS, $prefixes) . DS . $viewPath;
}
$this->viewPath = $viewPath;
}
if (!$request instanceof Request) {
$request = new Request();
}
$this->setRequest($request);
if (!$response instanceof Response) {
$response = new Response();
}
$this->response = $response;
if ($eventManager) {
$this->eventManager($eventManager);
}
$this->modelFactory('Table', ['Cake\\ORM\\TableRegistry', 'get']);
$modelClass = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
$this->_setModelClass($modelClass);
$this->initialize();
$this->_mergeControllerVars();
$this->_loadComponents();
$this->eventManager()->on($this);
}
示例10: _findTasks
/**
* Append matching tasks in $path to the $tasks array.
*
* @param array $tasks The task list to modify and return.
* @param string $path The base path to look in.
* @param string $namespace The base namespace.
* @param string|null $prefix The prefix to append.
* @return array Updated tasks.
*/
protected function _findTasks($tasks, $path, $namespace, $prefix = null)
{
$path .= 'Shell/Task';
if (!is_dir($path)) {
return $tasks;
}
$candidates = $this->_findClassFiles($path, $namespace);
$classes = $this->_findTaskClasses($candidates);
foreach ($classes as $class) {
list(, $name) = namespaceSplit($class);
$name = substr($name, 0, -4);
$fullName = ($prefix ? $prefix . '.' : '') . $name;
$tasks[$name] = $fullName;
}
return $tasks;
}
示例11: _method
/**
* Get method name
*
* @param Exception $exception Exception instance.
* @return string
*/
protected function _method(Exception $exception)
{
$exception = $this->_unwrap($exception);
list(, $baseClass) = namespaceSplit(get_class($exception));
if (substr($baseClass, -9) === 'Exception') {
$baseClass = substr($baseClass, 0, -9);
}
$method = Inflector::variable($baseClass) ?: 'error500';
return $this->method = $method;
}
示例12: _method
/**
* Get method name
*
* @param \Exception $exception Exception instance.
* @return string
*/
protected function _method(\Exception $exception)
{
list(, $baseClass) = namespaceSplit(get_class($exception));
$baseClass = substr($baseClass, 0, -9);
$method = Inflector::variable($baseClass) ?: 'error500';
return $this->method = $method;
}
示例13: name
/**
* Returns the type name name or sets a new one
*
* @param string $name the new type name
* @return string
*/
public function name($name = null)
{
if ($name !== null) {
$this->_name = $name;
}
if ($this->_name === null) {
$name = namespaceSplit(get_class($this));
$name = substr(end($name), 0, -4);
if (empty($name)) {
$name = '*';
}
$this->_name = Inflector::underscore($name);
}
return $this->_name;
}
示例14: _extractId
/**
* Extract the id from the theme class name.
*
* @return string
*/
protected function _extractId()
{
list(, $className) = namespaceSplit(get_class($this));
$id = explode('Theme', $className)[0];
if (!$className || !$id) {
user_error(__d('wasabi_cms', 'The theme class {0} has an invalid name. The name has to end with "Theme".', $className));
}
return $id;
}
示例15: _currentTable
/**
* Return current table in camelCase form.
* It adds plugin name as a prefix.
*
* @return string Table Name along with its prefix if found.
*/
protected function _currentTable()
{
list($namespace, $alias) = namespaceSplit(get_class($this));
$alias = substr($alias, 0, -5);
list($plugin) = explode('\\', $namespace);
if ($plugin === 'App') {
return Inflector::camelize($alias);
}
return Inflector::camelize($plugin . '.' . $alias);
}