Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
Строк: 101
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBundleFrameworkBundleRouting;

use 
SymfonyBundleFrameworkBundleControllerControllerNameParser;
use 
SymfonyComponentConfigLoaderDelegatingLoader as BaseDelegatingLoader;
use 
SymfonyComponentConfigLoaderLoaderResolverInterface;
use 
PsrLogLoggerInterface;
use 
SymfonyComponentRoutingRouteCollection;

/**
 * DelegatingLoader delegates route loading to other loaders using a loader resolver.
 *
 * This implementation resolves the _controller attribute from the short notation
 * to the fully-qualified form (from a:b:c to class:method).
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class DelegatingLoader extends BaseDelegatingLoader
{
    protected 
$parser;
    protected 
$logger;

    
/**
     * Constructor.
     *
     * @param ControllerNameParser    $parser   A ControllerNameParser instance
     * @param LoggerInterface         $logger   A LoggerInterface instance
     * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
     */
    
public function __construct(ControllerNameParser $parserLoggerInterface $logger nullLoaderResolverInterface $resolver)
    {
        
$this->parser $parser;
        
$this->logger $logger;

        
parent::__construct($resolver);
    }

    
/**
     * Loads a resource.
     *
     * @param mixed  $resource A resource
     * @param string $type     The resource type
     *
     * @return RouteCollection A RouteCollection instance
     */
    
public function load($resource$type null)
    {
        
$collection parent::load($resource$type);

        foreach (
$collection->all() as $route) {
            if (
$controller $route->getDefault('_controller')) {
                try {
                    
$controller $this->parser->parse($controller);
                } catch (
Exception $e) {
                    
// unable to optimize unknown notation
                
}

                
$route->setDefault('_controller'$controller);
            }
        }

        return 
$collection;
    }
}
Онлайн: 1
Реклама