本文整理汇总了PHP中Symfony\Component\HttpKernel\KernelInterface::getBundle方法的典型用法代码示例。如果您正苦于以下问题:PHP KernelInterface::getBundle方法的具体用法?PHP KernelInterface::getBundle怎么用?PHP KernelInterface::getBundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\KernelInterface
的用法示例。
在下文中一共展示了KernelInterface::getBundle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
/**
* @param string $source
* @param string $locale
*
* @return MessageCatalogueInterface | null
*/
public function extract($source, $locale)
{
if (!$this->isSourceAvailable($source)) {
return;
}
$fs = new Filesystem();
/* @var Bundle $foundBundle */
$foundBundle = $this->kernel->getBundle($this->bundle);
// load any messages from templates
$extractedCatalogue = new MessageCatalogue($locale);
$resourcesDir = $this->resolveResourcesDirectory($foundBundle);
if ($fs->exists($resourcesDir)) {
$this->extractor->extract($resourcesDir, $extractedCatalogue);
}
// load any existing messages from the translation files
$translationsDir = $foundBundle->getPath() . '/Resources/translations';
if ($fs->exists($translationsDir)) {
$currentCatalogue = new MessageCatalogue($locale);
$this->loader->loadMessages($translationsDir, $currentCatalogue);
foreach ($extractedCatalogue->getDomains() as $domain) {
$messages = $currentCatalogue->all($domain);
if (count($messages)) {
$extractedCatalogue->add($messages, $domain);
}
}
}
return $extractedCatalogue;
}
示例2: getRepository
/**
* {@inheritDoc}
*/
public function getRepository($name)
{
@(list($bundle, $name) = explode(':', $name));
if (!$name) {
return parent::getRepository($bundle);
}
$bundle = $this->kernel->getBundle($bundle);
return parent::getRepository($bundle->getNamespace() . '\\' . $name);
}
示例3: addMappingBundle
/**
* @param string $bundle
* @return $this
*/
public function addMappingBundle($bundle)
{
$path = $this->kernel->getBundle($bundle)->getPath();
$path .= DIRECTORY_SEPARATOR . 'Resources';
$path .= DIRECTORY_SEPARATOR . 'config';
$path .= DIRECTORY_SEPARATOR . 'doctrine';
$this->addMappingPath($path);
return $this;
}
示例4: locateResource
/**
* {@inheritdoc}
*
* @param string $resourcePath Eg. "@AcmeBundle/Resources/views/template.html.twig"
*/
public function locateResource($resourcePath, ThemeInterface $theme)
{
$this->assertResourcePathIsValid($resourcePath);
$bundleName = $this->getBundleNameFromResourcePath($resourcePath);
$resourceName = $this->getResourceNameFromResourcePath($resourcePath);
$bundles = $this->kernel->getBundle($bundleName, false);
foreach ($bundles as $bundle) {
$path = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName);
if ($this->filesystem->exists($path)) {
return $path;
}
}
throw new ResourceNotFoundException($resourcePath, $theme);
}
示例5: resolvePath
public function resolvePath(string $path) : string
{
$resourcePathExploded = explode('/', $path);
$resourcePathRoot = array_shift($resourcePathExploded);
if (strpos($resourcePathRoot, '@') === 0) {
$mappingFileBundle = ltrim($resourcePathRoot, '@');
$bundle = $this->kernel->getBundle($mappingFileBundle);
if ($bundle instanceof BundleInterface) {
$resourcePathRoot = $bundle->getPath();
}
}
array_unshift($resourcePathExploded, $resourcePathRoot);
return implode('/', $resourcePathExploded);
}
示例6: getFixturesByBundles
/**
*
* @return array
*/
protected function getFixturesByBundles()
{
if (empty($this->bundles)) {
throw new \RuntimeException('Bundles are not defined');
}
$paths = array();
foreach ($this->bundles as $name) {
$bundle = $this->kernel->getBundle($name);
if (!$bundle) {
throw new \RuntimeException(sprintf('unknown bundle %s', $bundle));
}
$paths[] = $bundle->getPath() . '/Resources/fixtures';
}
return $paths;
}
示例7: getBundlePaths
/**
* @param string $resourcePath
* @param ThemeInterface $theme
*/
protected function getBundlePaths($resourcePath, ThemeInterface $theme)
{
$bundleName = $this->getBundleNameFromResourcePath($resourcePath);
$resourceName = $this->getResourceNameFromResourcePath($resourcePath);
$bundles = $this->kernel->getBundle($bundleName, false);
$paths = [];
if (is_array($bundles)) {
foreach ($bundles as $bundle) {
if ($this->deviceDetection->getType() !== null) {
$paths[] = sprintf('%s/%s/%s/%s', $theme->getPath(), $this->deviceDetection->getType(), $bundle->getName(), $resourceName);
}
$paths[] = sprintf('%s/%s/%s', $theme->getPath(), $bundle->getName(), $resourceName);
}
}
return $paths;
}
示例8: getBundle
/**
* {@inheritdoc}
*/
public function getBundle($name, $first = true)
{
if (!empty($this->excludeBundleNames) && in_array($name, $this->excludeBundleNames)) {
throw new \InvalidArgumentException(sprintf('Bundle "%s" is in exclude list.', $name));
}
return $this->kernel->getBundle($name, $first);
}
示例9: updateKernel
/**
* {@inheritDoc}
* Add the new bundle to the BundleBundle loader infrastructure instead of main kernel
*
* @param QuestionHelper $questionHelper dialog
* @param InputInterface $input input
* @param OutputInterface $output output
* @param KernelInterface $kernel kernel
* @param string $namespace namespace
* @param string $bundle bundle
*
* @return string[]
*/
protected function updateKernel(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output, KernelInterface $kernel, $namespace, $bundle)
{
// skip if kernel manipulation disabled by options (defaults to true)
$doUpdate = $input->getOption('doUpdateKernel');
if ($doUpdate == 'false') {
return;
}
$auto = true;
if ($input->isInteractive()) {
$auto = $questionHelper->doAsk($output, $questionHelper->getQuestion('Confirm automatic update of your core bundle', 'yes', '?'));
}
$output->write('Enabling the bundle inside the core bundle: ');
$coreBundle = $kernel->getBundle($input->getOption('loaderBundleName'));
if (!is_a($coreBundle, '\\Graviton\\BundleBundle\\GravitonBundleInterface')) {
throw new \LogicException('GravitonCoreBundle does not implement GravitonBundleInterface');
}
$manip = new BundleBundleManipulator($coreBundle);
try {
$ret = $auto ? $manip->addBundle($namespace . '\\' . $bundle) : false;
if (!$ret) {
$reflected = new \ReflectionObject($kernel);
return array(sprintf('- Edit <comment>%s</comment>', $reflected->getFilename()), ' and add the following bundle in the <comment>GravitonCoreBundle::getBundles()</comment> method:', '', sprintf(' <comment>new %s(),</comment>', $namespace . '\\' . $bundle), '');
}
} catch (\RuntimeException $e) {
return array(sprintf('Bundle <comment>%s</comment> is already defined in <comment>%s)</comment>.', $namespace . '\\' . $bundle, 'sGravitonCoreBundle::getBundles()'), '');
}
}
示例10: array
function it_uses_suite_name_as_a_bundle_name_if_no_provided(KernelInterface $kernel, BundleInterface $bundle)
{
$kernel->getBundle('my_suite')->willReturn($bundle);
$suite = $this->generateSuite('my_suite', array());
$suite->shouldBeAnInstanceOf('Behat\\Symfony2Extension\\Suite\\SymfonyBundleSuite');
$suite->getBundle()->shouldReturn($bundle);
$suite->getSetting('bundle')->shouldReturn('my_suite');
}
示例11:
function it_locates_resource(PathCheckerInterface $pathChecker, KernelInterface $kernel, BundleInterface $bundle)
{
$bundle->getName()->willReturn("Bundle");
$bundle->getPath()->willReturn("/app/bundle");
$kernel->getBundle("Bundle", false)->willReturn([$bundle]);
$pathChecker->processPaths(Argument::type('array'), Argument::type('array'), [])->shouldBeCalled()->willReturn("/app/bundle/resource");
$this->locateResource("@Bundle/Resources/resource", [])->shouldReturn("/app/bundle/resource");
}
示例12: configure
/**
* If there is a parameter named like the driver locator path, replace it
* with the value of such parameter.
*
* @param SimpleDoctrineMappingLocator $locator Locator
*
* @throws ConfigurationInvalidException Configuration invalid
*/
public function configure(SimpleDoctrineMappingLocator $locator)
{
$path = $locator->getPaths()[0];
$resourcePathExploded = explode('/', $path);
$resourcePathRoot = array_shift($resourcePathExploded);
if (strpos($resourcePathRoot, '@') === 0) {
$mappingFileBundle = ltrim($resourcePathRoot, '@');
$bundle = $this->kernel->getBundle($mappingFileBundle);
if ($bundle instanceof BundleInterface) {
$resourcePathRoot = $bundle->getPath();
}
}
array_unshift($resourcePathExploded, $resourcePathRoot);
$path = implode('/', $resourcePathExploded);
if (!file_exists($path)) {
throw new ConfigurationInvalidException('Mapping file "' . $path . '" does not exist');
}
$locator->setPaths([$path]);
}
示例13: guessTemplateName
/**
* Guesses and returns the template name to render based on the controller
* and action names.
*
* @param array $controller An array storing the controller object and action method
* @param Request $request A Request instance
* @param string $engine
* @return TemplateReference template reference
* @throws \InvalidArgumentException
*/
public function guessTemplateName($controller, Request $request, $engine = 'twig')
{
$className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
if (!preg_match('/Controller\\\\(.+)Controller$/', $className, $matchController)) {
throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (it must be in a "Controller" sub-namespace and the class name must end with "Controller")', get_class($controller[0])));
}
if (!preg_match('/^(.+)Action$/', $controller[1], $matchAction)) {
throw new \InvalidArgumentException(sprintf('The "%s" method does not look like an action method (it does not end with Action)', $controller[1]));
}
$bundle = $this->getBundleForClass($className);
while ($bundleName = $bundle->getName()) {
if (null === ($parentBundleName = $bundle->getParent())) {
$bundleName = $bundle->getName();
break;
}
$bundles = $this->kernel->getBundle($parentBundleName, false);
$bundle = array_pop($bundles);
}
return new TemplateReference($bundleName, $matchController[1], $matchAction[1], $request->getRequestFormat(), $engine);
}
示例14: parse
/**
* {@inheritdoc}
*/
public function parse($name)
{
if ($name instanceof TemplateReferenceInterface) {
return $name;
} elseif (isset($this->cache[$name])) {
return $this->cache[$name];
}
if (!preg_match('/^(?:@([^\\/]*)|)(?:\\/(.+))?\\/(.+)\\.([^\\.]+)\\.([^\\.]+)$/', $name, $matches)) {
return $this->decoratedParser->parse($name);
}
$template = new TemplateReference($matches[1] ? $matches[1] . 'Bundle' : '', $matches[2], $matches[3], $matches[4], $matches[5]);
if ($template->get('bundle')) {
try {
$this->kernel->getBundle($template->get('bundle'));
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
}
}
return $this->cache[$name] = $template;
}
示例15:
function it_throws_an_exception_if_resource_can_not_be_located(Filesystem $filesystem, KernelInterface $kernel, ThemeInterface $theme, BundleInterface $childBundle, BundleInterface $parentBundle)
{
$kernel->getBundle('ParentBundle', false)->willReturn([$childBundle, $parentBundle]);
$childBundle->getName()->willReturn('ChildBundle');
$parentBundle->getName()->willReturn('ParentBundle');
$theme->getName()->willReturn('theme/name');
$theme->getPath()->willReturn('/theme/path');
$filesystem->exists('/theme/path/ChildBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false);
$filesystem->exists('/theme/path/ParentBundle/views/index.html.twig')->shouldBeCalled()->willReturn(false);
$this->shouldThrow(ResourceNotFoundException::class)->during('locateResource', ['@ParentBundle/Resources/views/index.html.twig', $theme]);
}