本文整理汇总了PHP中Nette\DI\Container::hasService方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::hasService方法的具体用法?PHP Container::hasService怎么用?PHP Container::hasService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\Container
的用法示例。
在下文中一共展示了Container::hasService方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getModel
/**
* getter for specified model
*
* @param string $name name of model
* @return BaseModel
* @throws \InvalidArgumentException
*/
public function getModel($name)
{
if ($this->container->hasService($name)) {
return $this->container->getService($name);
}
throw new \InvalidArgumentException("Model '{$name}' not found.");
}
示例2: uninstall
/**
* @param \Venne\Module\IModule $module
*/
public function uninstall(IModule $module)
{
if (!$this->context->hasService('doctrine') || !$this->context->doctrine->createCheckConnection()) {
throw new \Exception('Database connection not found!');
}
$classes = $this->getClasses($module);
$metadata = array();
foreach ($classes as $class) {
$metadata[] = $this->entityManager->getClassMetadata($class);
}
$tool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager);
$this->entityManager->getConnection()->beginTransaction();
try {
foreach ($classes as $class) {
$repository = $this->entityManager->getRepository($class);
foreach ($repository->findAll() as $entity) {
$repository->delete($entity);
}
}
$tool->dropSchema($metadata);
$this->entityManager->getConnection()->commit();
} catch (Exception $e) {
$this->entityManager->getConnection()->rollback();
$this->entityManager->close();
throw $e;
}
$this->cleanCache();
}
示例3: addWidget
/**
* @param string $name
* @param string $factory
*/
public function addWidget($name, $factory)
{
if (!is_string($name)) {
throw new InvalidArgumentException('Name of widget must be string');
}
if (!is_string($factory) && !method_exists($factory, 'create') && !is_callable($factory)) {
throw new InvalidArgumentException('Second argument must be string or factory or callable');
}
if (is_string($factory) && !$this->container->hasService($factory)) {
throw new InvalidArgumentException(sprintf('Service \'%s\' does not exist', $factory));
}
$this->widgets[$name] = $factory;
}
示例4: uninstall
/**
* @param IModule $module
*/
public function uninstall(IModule $module)
{
if (!$this->context->hasService('doctrine') || !$this->context->doctrine->createCheckConnection()) {
throw new \Exception('Database connection not found!');
}
$layouts = $this->templateManager->getLayoutsByModule($module->getName());
$repository = $this->getTemplateRepository();
foreach ($layouts as $path => $name) {
foreach ($repository->findBy(array('file' => $path)) as $entity) {
$repository->delete($entity);
}
}
}
示例5: injectComponentFactories
/**
* @param \Nette\DI\Container $dic
* @throws MemberAccessException
* @internal
*/
public function injectComponentFactories(Nette\DI\Container $dic)
{
if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) {
throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.');
}
$this->autowireComponentFactoriesLocator = $dic;
$storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage');
$cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireComponentFactories');
if ($cache->load($presenterClass = get_class($this)) !== NULL) {
return;
}
$ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter'];
$rc = new ClassType($this);
foreach ($rc->getMethods() as $method) {
if (in_array($method->getDeclaringClass()->getName(), $ignore, TRUE) || !Strings::startsWith($method->getName(), 'createComponent')) {
continue;
}
foreach ($method->getParameters() as $parameter) {
if (!($class = $parameter->getClassName())) {
// has object type hint
continue;
}
if (!$this->findByTypeForFactory($class) && !$parameter->allowsNull()) {
throw new MissingServiceException("No service of type {$class} found. Make sure the type hint in {$method} is written correctly and service of this type is registered.");
}
}
}
$files = array_map(function ($class) {
return ClassType::from($class)->getFileName();
}, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));
$files[] = ClassType::from($this->autowireComponentFactoriesLocator)->getFileName();
$cache->save($presenterClass, TRUE, [$cache::FILES => $files]);
}
示例6: injectProperties
/**
* @param \Nette\DI\Container $dic
* @throws MemberAccessException
* @throws MissingServiceException
* @throws InvalidStateException
* @throws UnexpectedValueException
*/
public function injectProperties(Nette\DI\Container $dic)
{
if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) {
throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.');
}
$this->autowirePropertiesLocator = $dic;
$storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage');
$cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireProperties');
$containerFileName = ClassType::from($this->autowirePropertiesLocator)->getFileName();
$cacheKey = [$presenterClass = get_class($this), $containerFileName];
if (is_array($this->autowireProperties = $cache->load($cacheKey))) {
foreach ($this->autowireProperties as $propName => $tmp) {
unset($this->{$propName});
}
return;
}
$this->autowireProperties = [];
$ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter'];
$rc = new ClassType($this);
foreach ($rc->getProperties() as $prop) {
if (!$this->validateProperty($prop, $ignore)) {
continue;
}
$this->resolveProperty($prop);
}
$files = array_map(function ($class) {
return ClassType::from($class)->getFileName();
}, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));
$files[] = $containerFileName;
$cache->save($cacheKey, $this->autowireProperties, [$cache::FILES => $files]);
}
示例7: formatPresenterFile
/**
* @param $presenter
* @return string
*/
public function formatPresenterFile($presenter)
{
$service = $this->formatPresenterFromServiceName($presenter);
if ($this->container->hasService($service)) {
return get_class($this->container->getService($service));
}
return parent::formatPresenterFile($presenter);
}
示例8: __isset
/**
* @return bool
*/
public function __isset($name)
{
return $this->container->hasService($this->namespace . $name);
}
示例9: has
/**
* @param string $name
* @return bool
*/
public function has($name)
{
return $this->container->hasService($name);
}
示例10: createServiceActionLogger
/**
* @param \Nette\DI\Container
* @return Utils\IActionLogger
*/
public static function createServiceActionLogger(Container $container)
{
if ($container->hasService('doctrineContainer')) {
return $container->doctrineContainer->getService('Nella\Utils\LoggerStorages\ActionEntity');
} else {
return new Utils\LoggerStorages\FileStorage;
}
}
示例11: createServiceConfiguration
/**
* @param \Nette\DI\Container
* @return \Doctrine\ORM\Configuration
*/
public static function createServiceConfiguration(DI\Container $context)
{
$config = new \Doctrine\ORM\Configuration;
// Cache
$storage = $context->hasService('metadataCache') ? $context->metadataCache : new Cache($context->cacheStorage);
$config->setMetadataCacheImpl($storage);
$storage = $context->hasService('queryCache') ? $context->queryCache : new Cache($context->cacheStorage);
$config->setQueryCacheImpl($storage);
// Metadata
$config->setClassMetadataFactoryName('Nella\Doctrine\Mapping\ClassMetadataFactory');
$config->setMetadataDriverImpl($context->annotationDriver);
// Proxies
$config->setProxyDir($this->configuration['proxyDir']);
$config->setProxyNamespace($this->configuration['proxyNamespace']);
if ($this->configuration['productionMode']) {
$config->setAutoGenerateProxyClasses(FALSE);
} else {
if ($context->hasService('logger')) {
$config->setSQLLogger($context->logger);
}
$config->setAutoGenerateProxyClasses(TRUE);
}
return $config;
}