Вход Регистрация
Файл: concrete5.7.5.6/concrete/vendor/zendframework/zend-servicemanager/src/Di/DiServiceFactory.php
Строк: 136
<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendServiceManagerDi;

use 
ZendDiDi;
use 
ZendDiExceptionClassNotFoundException as DiClassNotFoundException;
use 
ZendServiceManagerException;
use 
ZendServiceManagerFactoryInterface;
use 
ZendServiceManagerServiceLocatorInterface;

class 
DiServiceFactory extends Di implements FactoryInterface
{
    
/**@#+
     * constants
     */
    
const USE_SL_BEFORE_DI 'before';
    const 
USE_SL_AFTER_DI  'after';
    const 
USE_SL_NONE      'none';
    
/**@#-*/

    /**
     * @var ZendDiDi
     */
    
protected $di null;

    
/**
     * @var ZendDiInstanceManager
     */
    
protected $name null;

    
/**
     * @var array
     */
    
protected $parameters = array();

    
/**
     * @var string
     */
    
protected $useServiceLocator self::USE_SL_AFTER_DI;

    
/**
     * @var ServiceLocatorInterface
     */
    
protected $serviceLocator null;

    
/**
     * Constructor
     *
     * @param ZendDiDi $di
     * @param null|ZendDiInstanceManager $name
     * @param array $parameters
     * @param string $useServiceLocator
     */
    
public function __construct(Di $di$name, array $parameters = array(), $useServiceLocator self::USE_SL_NONE)
    {
        
$this->di $di;
        
$this->name $name;
        
$this->parameters $parameters;
        if (
in_array($useServiceLocator, array(self::USE_SL_BEFORE_DIself::USE_SL_AFTER_DIself::USE_SL_NONE))) {
            
$this->useServiceLocator $useServiceLocator;
        }

        
// since we are using this in a proxy-fashion, localize state
        
$this->definitions $this->di->definitions;
        
$this->instanceManager $this->di->instanceManager;
    }

    
/**
     * Create service
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @return object
     */
    
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        
$this->serviceLocator $serviceLocator;
        return 
$this->get($this->name$this->parameters);
    }

    
/**
     * Override, as we want it to use the functionality defined in the proxy
     *
     * @param string $name
     * @param array $params
     * @return object
     * @throws ExceptionServiceNotFoundException
     */
    
public function get($name, array $params = array())
    {
        
// allow this di service to get dependencies from the service locator BEFORE trying di
        
if ($this->useServiceLocator == self::USE_SL_BEFORE_DI && $this->serviceLocator->has($name)) {
            return 
$this->serviceLocator->get($name);
        }

        try {

            
$service parent::get($name$params);
            return 
$service;

        } catch (
DiClassNotFoundException $e) {

            
// allow this di service to get dependencies from the service locator AFTER trying di
            
if ($this->useServiceLocator == self::USE_SL_AFTER_DI && $this->serviceLocator->has($name)) {
                return 
$this->serviceLocator->get($name);
            } else {
                throw new 
ExceptionServiceNotFoundException(
                    
sprintf('Service %s was not found in this DI instance'$name),
                    
null,
                    
$e
                
);
            }
        }

    }
}
Онлайн: 1
Реклама