本文整理汇总了PHP中ClassRegistry::map方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassRegistry::map方法的具体用法?PHP ClassRegistry::map怎么用?PHP ClassRegistry::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClassRegistry
的用法示例。
在下文中一共展示了ClassRegistry::map方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructs this Shell instance.
*
*/
function __construct(&$dispatch)
{
$vars = array('params', 'args', 'shell', 'shellCommand' => 'command');
foreach ($vars as $key => $var) {
if (is_string($key)) {
$this->{$var} =& $dispatch->{$key};
} else {
$this->{$var} =& $dispatch->{$var};
}
}
if ($this->name == null) {
$this->name = get_class($this);
}
if ($this->alias == null) {
$this->alias = $this->name;
}
ClassRegistry::addObject($this->name, $this);
ClassRegistry::map($this->name, $this->alias);
if (!PHP5 && isset($this->args[0])) {
if (strpos($this->name, strtolower(Inflector::camelize($this->args[0]))) !== false) {
$dispatch->shiftArgs();
}
if (strtolower($this->command) == strtolower(Inflector::variable($this->args[0])) && method_exists($this, $this->command)) {
$dispatch->shiftArgs();
}
}
$this->Dispatch =& $dispatch;
}
示例2: loadTasks
/**
* Loads tasks defined in var $tasks
*
* @return bool
* @access public
*/
function loadTasks()
{
if ($this->tasks === null || $this->tasks === false) {
return;
}
if ($this->tasks !== true && !empty($this->tasks)) {
$tasks = $this->tasks;
if (!is_array($tasks)) {
$tasks = array($tasks);
}
foreach ($tasks as $taskName) {
$loaded = false;
foreach ($this->Dispatch->shellPaths as $path) {
$taskPath = $path . 'tasks' . DS . Inflector::underscore($taskName) . '.php';
if (file_exists($taskPath)) {
$loaded = true;
break;
}
}
if ($loaded) {
$taskKey = Inflector::underscore($taskName);
$taskClass = Inflector::camelize($taskName . 'Task');
if (!class_exists($taskClass)) {
require_once $taskPath;
}
if (ClassRegistry::isKeySet($taskKey)) {
$this->taskNames[] = $taskName;
if (!PHP5) {
$this->{$taskName} =& ClassRegistry::getObject($taskKey);
ClassRegistry::map($taskName, $taskKey);
} else {
$this->{$taskName} = ClassRegistry::getObject($taskKey);
ClassRegistry::map($taskName, $taskKey);
}
} else {
$this->taskNames[] = $taskName;
if (!PHP5) {
$this->{$taskName} =& new $taskClass($this->Dispatch);
} else {
$this->{$taskName} = new $taskClass($this->Dispatch);
}
}
if (!isset($this->{$taskName})) {
$this->err("Task '" . $taskName . "' could not be loaded");
exit;
}
} else {
$this->err("Task '" . $taskName . "' could not be found");
exit;
}
}
}
return false;
}
示例3: __construct
/**
* Constructs this Shell instance.
*
*/
public function __construct(&$dispatch)
{
$vars = array('params', 'args', 'shell', 'shellCommand' => 'command');
foreach ($vars as $key => $var) {
if (is_string($key)) {
$this->{$var} = $dispatch->{$key};
} else {
$this->{$var} = $dispatch->{$var};
}
}
if ($this->name == null) {
$this->name = get_class($this);
}
if ($this->alias == null) {
$this->alias = $this->name;
}
ClassRegistry::addObject($this->name, $this);
ClassRegistry::map($this->name, $this->alias);
$this->Dispatch = $dispatch;
}
示例4: __constructLinkedModel
/**
* Private helper method to create associated models of given class.
* @param string $assoc
* @param string $className Class name
* @param mixed $id Primary key ID of linked model
* @param string $table Database table associated with linked model
* @param string $ds Name of DataSource the model should be bound to
* @deprecated $this->$className use $this->$assoc instead. $assoc is the 'key' in the associations array;
* examples: var $hasMany = array('Assoc' => array('className' => 'ModelName'));
* usage: $this->Assoc->modelMethods();
*
* var $hasMany = array('ModelName');
* usage: $this->ModelName->modelMethods();
* @access private
*/
function __constructLinkedModel($assoc, $className = null)
{
$colKey = Inflector::underscore($assoc);
if (empty($className)) {
$className = $assoc;
}
if (!class_exists($className)) {
if (!loadModel($className)) {
return $this->cakeError('missingModel', array(array('className' => $className)));
}
}
$duplicate = false;
if (ClassRegistry::isKeySet($colKey)) {
$model = ClassRegistry::getObject($colKey);
if (is_a($model, $className)) {
$duplicate = true;
}
unset($model);
}
if ($duplicate === true) {
if (!PHP5) {
$this->{$assoc} =& ClassRegistry::getObject($colKey);
ClassRegistry::map($assoc, $colKey);
} else {
$this->{$assoc} = ClassRegistry::getObject($colKey);
ClassRegistry::map($assoc, $colKey);
}
} else {
$model = array('name' => $className, 'alias' => $assoc);
if (!PHP5) {
$this->{$assoc} =& new $className($model);
} else {
$this->{$assoc} = new $className($model);
}
}
$this->alias[$assoc] = $this->{$assoc}->table;
$this->tableToModel[$this->{$assoc}->table] = $className;
$this->modelToTable[$assoc] = $this->{$assoc}->table;
}
示例5:
<?php
/**
* CakePHP Container Interop Plugin initialization.
*
* Handles registering initialized container in ClassRegistry\
*/
use Interop\Container\ContainerInterface;
App::uses('ClassRegistry', 'Utility');
$containerFile = Configure::read(ContainerInterface::CLASS) ?: APP . 'Config/container.php';
ClassRegistry::addObject(ContainerInterface::CLASS, require $containerFile);
ClassRegistry::map('container', ContainerInterface::CLASS);
示例6: array
/**
* Get instance of model for translations
*
* @return object
*/
function &translateModel(&$model)
{
if (!isset($this->runtime[$model->name]['model'])) {
if (!isset($model->translateModel) || empty($model->translateModel)) {
$className = 'I18nModel';
} else {
$className = $model->translateModel;
if (!class_exists($className) && !loadModel($className)) {
return $this->cakeError('missingModel', array(array('className' => $className)));
}
}
if (ClassRegistry::isKeySet($className)) {
if (PHP5) {
$this->runtime[$model->name]['model'] = ClassRegistry::getObject($className);
} else {
$this->runtime[$model->name]['model'] =& ClassRegistry::getObject($className);
}
} else {
if (PHP5) {
$this->runtime[$model->name]['model'] = new $className();
} else {
$this->runtime[$model->name]['model'] =& new $className();
}
ClassRegistry::addObject($className, $this->runtime[$model->name]['model']);
ClassRegistry::map($className, $className);
}
}
return $this->runtime[$model->name]['model'];
}