/**
  * @param SourceNameInterface $sourceNameData
  *
  * @return CollectionInterface
  */
 public function createCollection(SourceNameInterface $sourceNameData)
 {
     if (!is_null($sourceNameData->getUsername()) || $sourceNameData->getSource() === SourceNameInterface::SOURCE_USER) {
         return $this->di->get('Frontend\\Service\\Instagram\\Images\\UserCollectionService', array('nameData' => $sourceNameData));
     }
     return $this->di->get('Frontend\\Service\\Instagram\\Images\\FeedCollectionService');
 }
Exemplo n.º 2
0
 public function postDispatchListener(\Zend\Mvc\MvcEvent $e)
 {
     $script = sprintf('var FB_APP_ID = "%s";', $this->getAppId());
     /** @var $view \Zend\View\PhpRenderer */
     $view = $this->locator->get('view');
     /** @var $headScript \Zend\View\Helper\HeadScript */
     $headScript = $view->plugin('HeadScript');
     $headScript->prependScript($script);
 }
Exemplo n.º 3
0
 /**
  * Run
  *
  * @return mixed
  */
 public function run()
 {
     $dic = new Model\DiC($this->_di);
     $dic->assemble();
     /** @var \App\Bot\Updater $updater */
     $botUpdater = $this->_di->get('BotUpdater');
     $botUpdater->checkUpdates();
     /** @var \App\Redmine\Updater $redmineUpdater */
     $redmineUpdater = $this->_di->get('RedmineUpdater');
     $redmineUpdater->checkUpdates();
 }
Exemplo n.º 4
0
 /**
  * Finds an entry of the container by its identifier and returns it
  *
  * @param string $name
  * @throws NotFoundException  No entry was found for this identifier
  * @return mixed
  */
 public function get($name)
 {
     $args = func_get_args();
     $arguments = isset($args[1]) ? $args[1] : [];
     if (isset($this->services[$name])) {
         return $this->services[$name];
     } elseif (isset($this->map[$name])) {
         return $this->map[$name]['shared'] ? $this->services[$name] = static::$di->get($this->map[$name]['class'], ['arguments' => $arguments]) : static::$di->newInstance($this->map[$name]['class'], ['arguments' => $arguments], false);
     } elseif (isset($this->callable[$name])) {
         return $this->callable[$name]($arguments);
     } else {
         throw new NotFoundException('Method ' . $name . '() not found');
     }
 }
Exemplo n.º 5
0
 /**
  * Handle Bot API updates
  *
  * @param array $updates Updates from Bot API
  *
  * @return void
  */
 public function handleBotApiUpdates(array $updates)
 {
     $updateId = $this->_lastUpdate->getBotUpdateId();
     foreach ($updates['result'] as $update) {
         $message = trim($this->_updateHelper->getMessageText($update));
         $updateId = $this->_updateHelper->getIncrementedUpdateId($update);
         if (!$this->_isCommandExist($this->_getCommandClassName($message))) {
             continue;
         }
         /** @var ICommand $commandModel */
         $commandModel = $this->_di->get($this->_getCommandClassName($message));
         $commandModel->execute($update);
     }
     $this->_lastUpdate->setData([Model\LastUpdate::UPDATE_COLUMN_NAME => $updateId])->saveBotUpdateId();
 }
Exemplo n.º 6
0
 public function createService(ServiceLocatorInterface $oServiceLocator)
 {
     $oServiceLocator = $oServiceLocator->getServiceLocator();
     $oAppService = $oServiceLocator->get('AppService');
     $oDi = new Di();
     $oDi->instanceManager()->setParameters('API\\Controller\\IndexController', array('app' => $oAppService));
     return $oDi->get('API\\Controller\\IndexController');
 }
Exemplo n.º 7
0
 public function get($class)
 {
     $class = $this->normalizeClassRequest($class);
     $preferredClass = $this->di->instanceManager()->getTypePreferences($class);
     if (is_array($preferredClass) && count($preferredClass) > 0) {
         $class = array_shift($preferredClass);
     }
     return $this->di->get($class);
 }
Exemplo n.º 8
0
 public function indexAction()
 {
     $config = $this->getServiceLocator('Configuration')->get('Configuration');
     $di = new Di(null, null, new Config($config['Di']));
     $basemodel = $di->get('NedVisol\\Orm\\BaseModel');
     $ret = $basemodel->adapter->putRow('test', array('id' => 'row2', 'columns' => array('cf1.a' => '234', 'cf1.b' => '456'), 'checks' => array('cf1.a' => '999')));
     echo "****{$ret}***";
     return new ViewModel();
 }
Exemplo n.º 9
0
 public function __invoke(array $config = array())
 {
     $di = new Di();
     $diConfig = array('definition' => array('class' => array('Zend\\Cache\\Storage\\Adapter' => array('instantiator' => array('Eva\\Cache\\StorageFactory', 'factory')), 'Eva\\Cache\\StorageFactory' => array('methods' => array('factory' => array('cfg' => array('required' => true, 'type' => false)))))), 'instance' => array('Eva\\Cache\\StorageFactory' => array('parameters' => array('cfg' => array('adapter' => array('name' => 'filesystem', 'options' => array('cacheDir' => EVA_ROOT_PATH . '/data/cache/model/')), 'plugins' => array('serializer'))))));
     $globalConfig = $this->serviceLocator->get('Configuration');
     $globalConfig = isset($globalConfig['cache']['model']) ? $globalConfig['cache']['model'] : array();
     $diConfig = Config::mergeArray($diConfig, $globalConfig, $config);
     $di->configure(new DiConfig($diConfig));
     return $di->get('Eva\\Cache\\StorageFactory');
 }
Exemplo n.º 10
0
 protected function __construct(Di $oDi)
 {
     $this->oJobQueueDb = $oDi->get('Classes\\Db\\JobQueue');
     $this->oBoxDb = $oDi->get('Classes\\Db\\Box');
     $this->oFolioDb = $oDi->get('Classes\\Db\\Folio');
     $this->oItemDb = $oDi->get('Classes\\Db\\Item');
     $this->oErrorLogDb = $oDi->get('Classes\\Db\\ErrorLog');
     $this->oFile = $oDi->get('Classes\\Helpers\\File');
     $this->oLogger = $oDi->get('Classes\\Helpers\\Logger');
 }
Exemplo n.º 11
0
 /**
  * @param Di $locator
  * @return mixed
  */
 public function doProxy(Di $locator)
 {
     $options = $this->getOptions();
     $result = null;
     if ('get' === $options['method']) {
         $result = $locator->get($options['name'], $options['params']);
     } elseif ('newInstance' === $options['method']) {
         $result = $locator->newInstance($options['name'], $options['params'], $options['isShared']);
     } else {
         throw new InvalidArgumentException("'{$options['method']}' is undefined method'");
     }
     return $result;
 }
Exemplo n.º 12
0
 /**
  * Override, as we want it to use the functionality defined in the proxy
  *
  * @param string $name
  * @param array $params
  * @return object
  * @throws Exception\InvalidServiceNameException
  */
 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 Exception\ServiceNotFoundException(sprintf('Service %s was not found in this DI instance', $name), null, $e);
         }
     }
 }
Exemplo n.º 13
0
 public static function factory(array $config = array())
 {
     $defaultConfig = array('di' => array('definition' => array(), 'instance' => array('Eva\\File\\Transfer\\Adapter\\Http' => array('parameters' => array()), 'Eva\\File\\Transfer\\Transfer' => array('parameters' => array('adapter' => 'Eva\\File\\Transfer\\Adapter\\Http')))));
     $globalConfig = Api::_()->getConfig();
     if (isset($globalConfig['file_transfer'])) {
         $config = array_merge($defaultConfig, $globalConfig['file_transfer'], $config);
     } else {
         $config = array_merge($defaultConfig, $config);
     }
     $diConfig = array();
     if ($config['di']) {
         $diConfig = $config['di'];
     }
     $di = new Di();
     $di->configure(new DiConfig($diConfig));
     $fileTransfer = $di->get('Eva\\File\\Transfer\\Transfer');
     //p($fileTransfer, 1);
     //@\Zend\Di\Display\Console::export($di);
     return $fileTransfer;
 }
Exemplo n.º 14
0
 /**
  * @group SharedInstance
  */
 public function testMarkingClassAsNotSharedInjectsNewInstanceIntoAllRequestersButDependentsAreShared()
 {
     $di = new Di();
     $di->configure(new Configuration(array('instance' => array('ZendTest\\Di\\TestAsset\\SharedInstance\\Lister' => array('shared' => false)))));
     $movie = $di->get('ZendTest\\Di\\TestAsset\\SharedInstance\\Movie');
     $venue = $di->get('ZendTest\\Di\\TestAsset\\SharedInstance\\Venue');
     $this->assertNotSame($movie->lister, $venue->lister);
     $this->assertSame($movie->lister->sharedLister, $venue->lister->sharedLister);
 }
Exemplo n.º 15
0
 public function getAuthStorage()
 {
     if ($this->authService) {
         return $this->authService->getStorage();
     }
     if ($this->authStorage) {
         return $this->authStorage;
     }
     $this->initStorage();
     $diConfig = $this->getDiConfig();
     $di = new Di();
     $di->configure(new DiConfig($diConfig));
     return $this->authStorage = $di->get($this->storageClass);
 }
Exemplo n.º 16
0
<?php

require_once './autoloader.php';
use Zend\Mail\Message;
use Zend\Mail\Transport;
use Zend\Di\Di;
use Zend\Di\Config as DiConfig;
$diConfig = array('instance' => array('Zend\\Mail\\Transport\\FileOptions' => array('parameters' => array('path' => __DIR__)), 'Zend\\Mail\\Transport\\File' => array('injections' => array('Zend\\Mail\\Transport\\FileOptions')), 'Zend\\Mail\\Transport\\SmtpOptions' => array('parameters' => array('name' => 'sendgrid', 'host' => 'smtp.sendgrid.net', 'port' => 25, 'connectionClass' => 'login', 'connectionConfig' => array('username' => '*****@*****.**', 'password' => 'password'))), 'Zend\\Mail\\Message' => array('parameters' => array('headers' => 'Zend\\Mail\\Headers', 'Zend\\Mail\\Message::setTo:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setTo:name' => 'EvaEngine', 'Zend\\Mail\\Message::setFrom:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setFrom:name' => 'EvaEngine', 'setBody' => 'Zend\\View\\Renderer\\PhpRenderer::render')), 'Zend\\Mail\\Transport\\Smtp' => array('injections' => array('Zend\\Mail\\Transport\\SmtpOptions'))));
$di = new Di();
$di->configure(new DiConfig($diConfig));
$transport = $di->get('Zend\\Mail\\Transport\\Smtp');
$transport = $di->get('Zend\\Mail\\Transport\\Sendmail');
$transport = $di->get('Zend\\Mail\\Transport\\File');
$message = $di->get('Zend\\Mail\\Message');
$view = new Zend\View\Renderer\PhpRenderer();
$resolver = new Zend\View\Resolver\TemplatePathStack();
$resolver->setPaths(array('mailTemplate' => __DIR__));
$view->setResolver($resolver);
$viewModel = new Zend\View\Model\ViewModel();
$viewModel->setTemplate('mail/template')->setVariables(array('user' => 'AlloVince'));
$message->setSubject("Zend Mail with Template")->setBody($view->render($viewModel));
$transport->send($message);
Exemplo n.º 17
0
 /**
  * @group ZF2-260
  */
 public function testDiWillInjectClassNameAsStringAtCallTime()
 {
     $di = new Di();
     $classDef = new Definition\ClassDefinition('ZendTest\\Di\\TestAsset\\SetterInjection\\D');
     $classDef->addMethod('setA', true);
     $classDef->addMethodParameter('setA', 'a', array('type' => false, 'required' => true));
     $di->definitions()->addDefinition($classDef, false);
     $d = $di->get('ZendTest\\Di\\TestAsset\\SetterInjection\\D', array('a' => 'ZendTest\\Di\\TestAsset\\SetterInjection\\A'));
     $this->assertSame($d->a, 'ZendTest\\Di\\TestAsset\\SetterInjection\\A');
 }
 /**
  * Overrides Zend\Di to allow the given serviceLocator's services to be reused by Di itself
  *
  * {@inheritDoc}
  *
  * @throws Exception\InvalidServiceNameException
  */
 public function get($name, array $params = array())
 {
     if (null === $this->serviceLocator) {
         throw new DomainException('No ServiceLocator defined, use `createServiceWithName` instead of `get`');
     }
     if (self::USE_SL_BEFORE_DI === $this->useServiceLocator && $this->serviceLocator->has($name)) {
         return $this->serviceLocator->get($name);
     }
     try {
         return parent::get($name, $params);
     } catch (ClassNotFoundException $e) {
         if (self::USE_SL_AFTER_DI === $this->useServiceLocator && $this->serviceLocator->has($name)) {
             return $this->serviceLocator->get($name);
         }
         throw new Exception\ServiceNotFoundException(sprintf('Service %s was not found in this DI instance', $name), null, $e);
     }
 }
Exemplo n.º 19
0
 /**
  * @group SharedInstance
  */
 public function testGetWithParamsWillUseSharedInstance()
 {
     $di = new Di();
     $sharedInstanceClass = 'ZendTest\\Di\\TestAsset\\ConstructorInjection\\A';
     $retrievedInstanceClass = 'ZendTest\\Di\\TestAsset\\ConstructorInjection\\C';
     // Provide definitions for $retrievedInstanceClass, but not for $sharedInstanceClass.
     $arrayDefinition = array($retrievedInstanceClass => array('supertypes' => array(), 'instantiator' => '__construct', 'methods' => array('__construct' => true), 'parameters' => array('__construct' => array("{$retrievedInstanceClass}::__construct:0" => array('a', $sharedInstanceClass, true, NULL), "{$retrievedInstanceClass}::__construct:1" => array('params', NULL, false, array())))));
     // This also disables scanning of class A.
     $di->setDefinitionList(new DefinitionList(new Definition\ArrayDefinition($arrayDefinition)));
     $di->instanceManager()->addSharedInstance(new $sharedInstanceClass(), $sharedInstanceClass);
     $returnedC = $di->get($retrievedInstanceClass, array('params' => array('test')));
     $this->assertInstanceOf($retrievedInstanceClass, $returnedC);
 }
Exemplo n.º 20
0
 public function testAliasesWithDeffrentParams()
 {
     $config = array('instance' => array('preference' => array('ZendTest\\Di\\TestAsset\\ConstructorInjection\\A' => 'ZendTest\\Di\\TestAsset\\ConstructorInjection\\E')));
     $di = new Di(null, null, new Config($config));
     $im = $di->instanceManager();
     $im->addAlias('foo', 'ZendTest\\Di\\TestAsset\\ConstructorInjection\\F', array('params' => array('p' => 'vfoo')));
     $im->addAlias('bar', 'ZendTest\\Di\\TestAsset\\ConstructorInjection\\F', array('params' => array('p' => 'vbar')));
     $pref = $di->get('ZendTest\\Di\\TestAsset\\ConstructorInjection\\B');
     $bFoo = $di->get('ZendTest\\Di\\TestAsset\\ConstructorInjection\\B', array('a' => 'foo'));
     $bBar = $di->get('ZendTest\\Di\\TestAsset\\ConstructorInjection\\B', array('a' => 'bar'));
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\ConstructorInjection\\E', $pref->a);
     $this->assertNotSame($pref->a, $bFoo->a);
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\ConstructorInjection\\F', $bFoo->a);
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\ConstructorInjection\\F', $bBar->a);
     $this->assertEquals('vfoo', $bFoo->a->params['p']);
     $this->assertEquals('vbar', $bBar->a->params['p']);
 }
Exemplo n.º 21
0
 /**
  * Retrieve cached object instance
  *
  * @param string $className
  * @param array $arguments
  * @return object
  */
 public function get($className, array $arguments = array())
 {
     $object = $this->_di->get($className, $arguments);
     return $object;
 }
Exemplo n.º 22
0
<?php

require_once './autoloader.php';
use Zend\Mail\Message;
use Zend\Mail\Transport;
use Zend\Di\Di;
use Zend\Di\Config as DiConfig;
use Zend\Mime\Message as MimeMessage;
use Zend\Mime\Part;
$diConfig = array('instance' => array('Zend\\View\\Resolver\\TemplatePathStack' => array('parameters' => array('paths' => array('mailTemplate' => __DIR__ . '/'))), 'Zend\\View\\Renderer\\PhpRenderer' => array('parameters' => array('resolver' => 'Zend\\View\\Resolver\\TemplatePathStack')), 'Zend\\View\\Model\\ViewModel' => array('parameters' => array('template' => 'mail/template')), 'Zend\\Mail\\Transport\\FileOptions' => array('parameters' => array('path' => __DIR__)), 'Zend\\Mail\\Transport\\File' => array('injections' => array('Zend\\Mail\\Transport\\FileOptions')), 'Zend\\Mail\\Transport\\SmtpOptions' => array('parameters' => array('name' => 'sendgrid', 'host' => 'smtp.sendgrid.net', 'port' => 25, 'connectionClass' => 'login', 'connectionConfig' => array('username' => '*****@*****.**', 'password' => 'password'))), 'Zend\\Mail\\Message' => array('parameters' => array('headers' => 'Zend\\Mail\\Headers', 'Zend\\Mail\\Message::setTo:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setTo:name' => 'EvaEngine', 'Zend\\Mail\\Message::setFrom:emailOrAddressList' => '*****@*****.**', 'Zend\\Mail\\Message::setFrom:name' => 'EvaEngine', 'setBody' => 'Zend\\View\\Renderer\\PhpRenderer::render')), 'Zend\\Mail\\Transport\\Smtp' => array('injections' => array('Zend\\Mail\\Transport\\SmtpOptions'))));
$di = new Di();
$di->configure(new DiConfig($diConfig));
$transport = $di->get('Zend\\Mail\\Transport\\Smtp');
$transport = $di->get('Zend\\Mail\\Transport\\File');
$view = $di->get('Zend\\View\\Renderer\\PhpRenderer');
$viewModel = $di->get('Zend\\View\\Model\\ViewModel');
$viewModel->setVariables(array('user' => 'AlloVince'));
$mimeMessage = new MimeMessage();
$messageText = new Part($view->render($viewModel));
$messageText->type = 'text/plain';
$data = fopen('loading.jpg', 'r');
$messageAttachment = new Part($data);
$messageAttachment->type = 'image/jpg';
$messageAttachment->filename = 'loading.jpg';
$messageAttachment->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
$messageAttachment->disposition = \Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
/*
$file = iconv("UTF-8","gb2312", '新建文本文档.txt');
$data = fopen($file, 'r');
$messageTextAttachment = new Part($data);
$messageTextAttachment->filename = '新建文本文档.txt';
Exemplo n.º 23
0
    public function testInjectionForSetterInjectionWillNotUseSupertypeWhenChildParamIsExplicitlyDefined()
    {
        $di = new Di();
        // for setter injection, the dependency is not required, thus it must be forced
        $di->instanceManager()->setParameters(
            'ZendTest\Di\TestAsset\InheritanceClasses\B',
            array('test' => 'b')
        );
        $di->instanceManager()->setParameters(
            'ZendTest\Di\TestAsset\InheritanceClasses\A',
            array('test' => 'a')
        );

        $b = $di->get('ZendTest\Di\TestAsset\InheritanceClasses\B');
        $this->assertEquals('b', $b->test);

        $c = $di->get('ZendTest\Di\TestAsset\InheritanceClasses\C');
        $this->assertEquals('b', $c->test);
    }
Exemplo n.º 24
0
 public function __construct(array $config = array())
 {
     $defaultConfig = array('transports' => array('smtp' => false, 'sendmail' => false, 'file' => true), 'message' => array(), 'di' => array('definition' => array('class' => array('Zend\\View\\Resolver\\AggregateResolver' => array('attach' => array('resolver' => array('required' => true, 'type' => 'Zend\\View\\Resolver\\TemplatePathStack'))))), 'instance' => array('Zend\\View\\Resolver\\TemplatePathStack' => array('parameters' => array('paths' => array(Message::VIEW_PATH_NAME => EVA_ROOT_PATH . '/data/'))), 'Zend\\View\\Resolver\\AggregateResolver' => array('injections' => array('Zend\\View\\Resolver\\TemplatePathStack')), 'Zend\\View\\Renderer\\PhpRenderer' => array('parameters' => array('resolver' => 'Zend\\View\\Resolver\\AggregateResolver')), 'Eva\\Mail\\Message' => array('parameters' => array('headers' => 'Zend\\Mail\\Headers', 'view' => 'Zend\\View\\Renderer\\PhpRenderer', 'viewModel' => 'Zend\\View\\Model\\ViewModel', 'encoding' => 'UTF-8')), 'Zend\\Mail\\Transport\\FileOptions' => array('parameters' => array('path' => EVA_ROOT_PATH . '/data/mail')), 'Zend\\Mail\\Transport\\File' => array('injections' => array('Zend\\Mail\\Transport\\FileOptions')), 'Zend\\Mail\\Transport\\Smtp' => array('injections' => array('Zend\\Mail\\Transport\\SmtpOptions')))));
     $globalConfig = Api::_()->getConfig();
     if (isset($globalConfig['mail'])) {
         $config = Config::mergeArray($defaultConfig, $globalConfig['mail'], $config);
     } else {
         $config = Config::mergeArray($defaultConfig['mail'], $config);
     }
     $diConfig = array();
     if ($config['di']) {
         $diConfig = $config['di'];
     }
     $di = new Di();
     $di->configure(new DiConfig($diConfig));
     $this->message = $di->get('Eva\\Mail\\Message');
     $allowTransports = $this->transportsClasses;
     $transportType = '';
     if (is_string($config['transports'])) {
         $transportType = $config['transports'];
         $transportClass = isset($allowTransports[$transportType]) ? $allowTransports[$transportType] : null;
         if (!$transportClass) {
             throw new Exception\InvalidArgumentException(sprintf('Unknow transport type %s in method %s"', $transportType, __METHOD__));
         }
         $transport = $di->get($transportClass);
         //\Zend\Di\Display\Console::export($di);
         $this->transports[$transportType] = $transport;
     } elseif (is_array($config['transports'])) {
         $transportTypes = $config['transports'];
         foreach ($transportTypes as $transportType => $value) {
             if (!$value) {
                 continue;
             }
             $transportClass = isset($allowTransports[$transportType]) ? $allowTransports[$transportType] : null;
             if (!$transportClass) {
                 throw new Exception\InvalidArgumentException(sprintf('Unknow transport type %s in method %s"', $transportType, __METHOD__));
             }
             $this->transports[$transportType] = $di->get($transportClass);
         }
     } else {
         throw new Exception\InvalidArgumentException(sprintf('%s expects a string or array as transport config, "%s" received', __METHOD__, gettype($config['transports'])));
     }
 }
 /**
  * {@inheritDoc}
  * @return GeneratorInstance
  */
 public function get($name, array $params = array())
 {
     return parent::get($name, $params);
 }
Exemplo n.º 26
0
<?php

namespace MovieApp {
    class Lister
    {
        public $finder;
        public function __construct(Finder $finder)
        {
            $this->finder = $finder;
        }
    }
    class Finder
    {
    }
}
namespace {
    // bootstrap
    include 'zf2bootstrap' . (stream_resolve_include_path('zf2bootstrap.php') ? '.php' : '.dist.php');
    use Zend\Di\Di, Zend\Di\DefinitionList, Zend\Di\Definition\BuilderDefinition;
    $builderDefinition = new BuilderDefinition();
    $builderDefinition->createClassesFromArray(array('MovieApp\\Lister' => array('methods' => array('__construct' => array('repo' => 'MovieApp\\Finder'))), 'MovieApp\\Finder' => array()));
    $di = new Di(new DefinitionList(array($builderDefinition)));
    $lister = $di->get('MovieApp\\Lister');
    // expression to test
    $works = $lister->finder instanceof MovieApp\Finder;
    // display result
    echo $works ? 'It works!' : 'It DOES NOT work!';
}
Exemplo n.º 27
0
 /**
  * Assemble bot commands
  *
  * @return void
  */
 private function _assembleBotCommands()
 {
     $this->_im->setParameters('App\\Bot\\CommandAbstract', ['botApi' => $this->_di->get('BotApi')]);
     $this->_im->setParameters('App\\Bot\\Command\\Register', ['chat' => $this->_di->get('Chat'), 'userIssue' => $this->_di->get('UserIssue'), 'userKey' => $this->_di->get('UserKey')]);
     $this->_im->setParameters('App\\Bot\\Command\\Deregister', ['chat' => $this->_di->get('Chat')]);
 }
 /**
  * Override, as we want it to use the functionality defined in the proxy.
  *
  * @param string $name
  * @param array $params
  * @return object
  * @throws Exception\ServiceNotFoundException
  */
 public function get($name, array $params = [])
 {
     // Allow this di service to get dependencies from the service locator BEFORE trying DI.
     if ($this->useContainer == self::USE_SL_BEFORE_DI && $this->container->has($name)) {
         return $this->container->get($name);
     }
     try {
         return parent::get($name, $params);
     } catch (DiClassNotFoundException $e) {
         // allow this di service to get dependencies from the service locator AFTER trying di
         if ($this->useContainer !== self::USE_SL_AFTER_DI || $this->container->has($name)) {
             throw new Exception\ServiceNotFoundException(sprintf('Service %s was not found in this DI instance', $name), null, $e);
         }
     }
     return $this->container->get($name);
 }
Exemplo n.º 29
0
 /**
  * @group SetterInjection
  * @group SupertypeResolution
  */
 public function testInjectionForSetterInjectionWillConsultSupertypeDefinitionInClassDefinition()
 {
     $di = new Di();
     // for setter injection, the dependency is not required, thus it must be forced
     $classDef = new Definition\ClassDefinition('ZendTest\\Di\\TestAsset\\SetterInjection\\B');
     $classDef->addMethod('setA', true);
     $di->definitions()->addDefinition($classDef, false);
     // top of stack b/c Runtime is already there
     $c = $di->get('ZendTest\\Di\\TestAsset\\SetterInjection\\C');
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\SetterInjection\\C', $c);
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\SetterInjection\\A', $c->a);
 }
Exemplo n.º 30
0
    public function testDiWillInjectDependenciesForAlias()
    {
        $di = new Di;

        // for setter injection, the dependency is not required, thus it must be forced
        $classDef = new Definition\ClassDefinition('ZendTest\Di\TestAsset\SetterInjection\B');
        $classDef->addMethod('setA', false);
        $classDef->addMethodParameter('setA', 'a', array('type' => 'ZendTest\Di\TestAsset\SetterInjection\A', 'required' => false));
        $di->definitions()->addDefinition($classDef, false);
        $di->instanceManager()->addAlias('b_alias', 'ZendTest\Di\TestAsset\SetterInjection\B');
        $di->instanceManager()->setInjections('b_alias', array('ZendTest\Di\TestAsset\SetterInjection\A'));

        $b = $di->get('b_alias');
        $this->assertInstanceOf('ZendTest\Di\TestAsset\SetterInjection\A', $b->a);
    }