本文整理匯總了PHP中Zend\Di\Di::get方法的典型用法代碼示例。如果您正苦於以下問題:PHP Di::get方法的具體用法?PHP Di::get怎麽用?PHP Di::get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Di\Di
的用法示例。
在下文中一共展示了Di::get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createCollection
/**
* @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');
}
示例2: postDispatchListener
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);
}
示例3: run
/**
* 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();
}
示例4: get
/**
* 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');
}
}
示例5: handleBotApiUpdates
/**
* 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();
}
示例6: createService
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');
}
示例7: get
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);
}
示例8: indexAction
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();
}
示例9: __invoke
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');
}
示例10: __construct
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');
}
示例11: doProxy
/**
* @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;
}
示例12: get
/**
* 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);
}
}
}
示例13: factory
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;
}
示例14: testMarkingClassAsNotSharedInjectsNewInstanceIntoAllRequestersButDependentsAreShared
/**
* @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);
}
示例15: getAuthStorage
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);
}