/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
<?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);
/** * 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']; }