本文整理汇总了PHP中Craft::createComponent方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::createComponent方法的具体用法?PHP Craft::createComponent怎么用?PHP Craft::createComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::createComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRoute
/**
* @param $route
*
* @return null
*/
public function addRoute($route)
{
$counter = count($this->_routes);
$route = Craft::createComponent($route);
$route->init();
$this->_routes[$counter] = $route;
}
示例2: createCommand
/**
* @param string $name command name (case-insensitive)
* @return \CConsoleCommand the command object. Null if the name is invalid.
*/
public function createCommand($name)
{
$name = strtolower($name);
$command = null;
if (isset($this->commands[$name])) {
$command = $this->commands[$name];
} else {
$commands = array_change_key_case($this->commands);
if (isset($commands[$name])) {
$command = $commands[$name];
}
}
if ($command !== null) {
if (is_string($command)) {
if (strpos($command, '/') !== false || strpos($command, '\\') !== false) {
$className = IOHelper::getFileName($command, false);
// If it's a default framework command, don't namespace it.
if (strpos($command, 'framework') === false) {
$className = __NAMESPACE__ . '\\' . $className;
}
if (!class_exists($className, false)) {
require_once $command;
}
} else {
$className = Craft::import($command);
}
return new $className($name, $this);
} else {
return Craft::createComponent($command, $name, $this);
}
} else {
if ($name === 'help') {
return new \CHelpCommand('help', $this);
} else {
return null;
}
}
}
示例3: createController
/**
* Creates a controller instance based on a route.
*
* @param string $route
* @param mixed $owner
* @return array|null
*/
public function createController($route, $owner = null)
{
if (($route = trim($route, '/')) === '') {
$route = $this->defaultController;
}
$routeParts = array_filter(explode('/', $route));
// First check if the controller class is a combination of the first two segments.
// That way FooController won't steal all of Foo_BarController's requests.
if (isset($routeParts[1])) {
$controllerId = ucfirst($routeParts[0]) . '_' . ucfirst($routeParts[1]);
$class = __NAMESPACE__ . '\\' . $controllerId . 'Controller';
if (class_exists($class)) {
$action = implode('/', array_slice($routeParts, 2));
}
}
// If that didn't work, now look for that FooController.
if (!isset($action)) {
$controllerId = ucfirst($routeParts[0]);
$class = __NAMESPACE__ . '\\' . $controllerId . 'Controller';
if (class_exists($class)) {
$action = implode('/', array_slice($routeParts, 1));
}
}
// Did we find a valid controller?
if (isset($action)) {
return array(Craft::createComponent($class, $controllerId), $this->parseActionParams($action));
}
}