本文整理汇总了PHP中ServiceUtil::hasContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceUtil::hasContainer方法的具体用法?PHP ServiceUtil::hasContainer怎么用?PHP ServiceUtil::hasContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceUtil
的用法示例。
在下文中一共展示了ServiceUtil::hasContainer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
/**
* Load routes of the specified module from the module's configuration file.
*
* @param AbstractBundle $bundle
*
* @return RouteCollection[]
*/
private function find(AbstractBundle $bundle)
{
if (!\ServiceUtil::hasContainer()) {
\ServiceUtil::setContainer($this->container);
}
try {
$path = $this->zikulaKernel->locateResource($bundle->getRoutingConfig());
} catch (\InvalidArgumentException $e) {
// Routing file does not exist (e.g. because the bundle could not be located).
return [new RouteCollection(), new RouteCollection(), new RouteCollection()];
}
$name = $bundle->getName();
$topRouteCollection = new RouteCollection();
$middleRouteCollection = new RouteCollection();
$bottomRouteCollection = new RouteCollection();
/**
* These are all routes of the module, as loaded by Symfony.
* @var RouteCollection $routeCollection
*/
$routeCollection = $this->import($path);
// Add all resources from the imported route collection to the middleRouteCollection.
// The actual collection (top, middle, bottom) to add the resources too does not matter,
// they just must be added to one of them, so that they don't get lost.
foreach ($routeCollection->getResources() as $resource) {
$middleRouteCollection->addResource($resource);
}
// It would be great to auto-reload routes here if the module version changes or a module is uninstalled.
// This is not yet possible, see
// - https://github.com/symfony/symfony/issues/7176
// - https://github.com/symfony/symfony/pull/15738
// - https://github.com/symfony/symfony/pull/15692
// $routeCollection->addResource(new ZikulaResource())
/** @var Route $route */
foreach ($routeCollection as $oldRouteName => $route) {
// set break here with $oldRouteName == 'zikula_routesmodule_route_renew'
$this->fixRequirements($route);
$this->prependBundlePrefix($route, $bundle);
list($type, $func) = $this->setZikulaDefaults($route, $bundle, $name);
$routeName = $this->getRouteName($oldRouteName, $name, $type, $func);
if ($route->hasOption('zkPosition')) {
switch ($route->getOption('zkPosition')) {
case 'top':
$topRouteCollection->add($routeName, $route);
break;
case 'bottom':
$bottomRouteCollection->add($routeName, $route);
break;
default:
throw new \RuntimeException('Unknown route position. Got "' . $route->getOption('zkPosition') . '", expected "top" or "bottom"');
}
} else {
$middleRouteCollection->add($routeName, $route);
}
}
return [$middleRouteCollection, $topRouteCollection, $bottomRouteCollection];
}
示例2: getPathWithBundlePrefix
/**
* Returns the route's path prepended with the bundle prefix.
*
* @param null $container Can be used to set the container for \ServiceUtil in case it is not already set.
*
* @return string
*/
public function getPathWithBundlePrefix($container = null)
{
if (!isset($this->options['zkNoBundlePrefix']) || !$this->options['zkNoBundlePrefix']) {
$bundle = $this->getBundle();
if (!\ServiceUtil::hasContainer()) {
\ServiceUtil::setContainer($container);
}
$modinfo = \ModUtil::getInfoFromName($bundle);
return "/" . $modinfo["url"] . $this->path;
}
return $this->path;
}