Prado\PradoBase::createComponent PHP Метод

createComponent() публичный статический Метод

A component type can be either the component class name or a namespace referring to the path of the component class file. For example, 'TButton', '\Prado\Web\UI\WebControls\TButton' are both valid component type. This method can also pass parameters to component constructors. All parameters passed to this method except the first one (the component type) will be supplied as component constructor parameters.
public static createComponent ( $requestedType ) : TComponent
Результат TComponent component instance of the specified type
    public static function createComponent($requestedType)
    {
        $type = static::prado3NamespaceToPhpNamespace($requestedType);
        if (!isset(self::$classExists[$type])) {
            self::$classExists[$type] = class_exists($type, false);
        }
        if (!isset(self::$_usings[$type]) && !self::$classExists[$type]) {
            static::using($type);
            self::$classExists[$type] = class_exists($type, false);
        }
        /*
         * Old apps compatibility support: if the component name has been specified using the 
         * old namespace syntax (eg. Application.Common.MyDataModule), assume that the calling
         * code expects the class not to be php5.3-namespaced (eg: MyDataModule instead of
         * \Application\Common\MyDataModule)
         * Skip this if the class is inside the Prado\* namespace, since all Prado classes are now namespaced
         */
        if (($pos = strrpos($type, '\\')) !== false && $requestedType != $type && strpos($type, 'Prado\\') !== 0) {
            $type = substr($type, $pos + 1);
        }
        if (($n = func_num_args()) > 1) {
            $args = func_get_args();
            switch ($n) {
                case 2:
                    return new $type($args[1]);
                    break;
                case 3:
                    return new $type($args[1], $args[2]);
                    break;
                case 4:
                    return new $type($args[1], $args[2], $args[3]);
                    break;
                case 5:
                    return new $type($args[1], $args[2], $args[3], $args[4]);
                    break;
                default:
                    $s = '$args[1]';
                    for ($i = 2; $i < $n; ++$i) {
                        $s .= ",\$args[{$i}]";
                    }
                    eval("\$component=new {$type}({$s});");
                    return $component;
                    break;
            }
        } else {
            return new $type();
        }
    }