当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::underscore方法代码示例

本文整理汇总了PHP中Symfony\Component\DependencyInjection\Container::underscore方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::underscore方法的具体用法?PHP Container::underscore怎么用?PHP Container::underscore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DependencyInjection\Container的用法示例。


在下文中一共展示了Container::underscore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 public function generate($namespace, $bundle, $dir, $format)
 {
     //      $dir .= '/'.strtr($namespace, '\\', '/');
     if (file_exists($dir)) {
         if (!is_dir($dir)) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" exists
             but is a file.', realpath($dir)));
         }
         //          $files = scandir($dir);
         //          if ($files != array('.', '..', 'composer.json', 'composer.lock', 'composer.phar', 'parameters.yml', 'vendor')) {
         //              throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.', realpath($dir)));
         //          }
         if (!is_writable($dir)) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not
             writable.', realpath($dir)));
         }
     }
     $basename = substr($bundle, 0, -6);
     $parameters = array('namespace' => $namespace, 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $basename, 'extension_alias' => Container::underscore($basename));
     $this->renderFile('bundle/Bundle.php.twig', $dir . '/' . $bundle . '.php', $parameters);
     $this->renderFile('bundle/Extension.php.twig', $dir . '/DependencyInjection/' . $basename . 'Extension.php', $parameters);
     $this->renderFile('bundle/Configuration.php.twig', $dir . '/DependencyInjection/Configuration.php', $parameters);
     $this->renderFile('bundle/DefaultController.php.twig', $dir . '/Controller/DefaultController.php', $parameters);
     $this->renderFile('bundle/DefaultControllerTest.php.twig', $dir . '/Tests/Controller/DefaultControllerTest.php', $parameters);
     $this->renderFile('bundle/index.html.twig.twig', $dir . '/Resources/views/Default/index.html.twig', $parameters);
     if ('xml' === $format || 'annotation' === $format) {
         $this->renderFile('bundle/services.xml.twig', $dir . '/Resources/config/services.xml', $parameters);
     } else {
         $this->renderFile('bundle/services.' . $format . '.twig', $dir . '/Resources/config/services.' . $format, $parameters);
     }
     if ('annotation' != $format) {
         $this->renderFile('bundle/routing.' . $format . '.twig', $dir . '/Resources/config/routing.' . $format, $parameters);
     }
 }
开发者ID:ErikZigo,项目名称:syrup,代码行数:34,代码来源:ComponentGenerator.php

示例2: generate

 public function generate($namespace, $bundle, $dir, $format, $structure)
 {
     $dir .= '/' . str_replace('\\', '/', $namespace);
     if (file_exists($dir)) {
         throw new \RuntimeException(sprintf('Le repertoire du bundle existe deja.', realpath($dir)));
     }
     $basename = substr($bundle, 0, -6);
     $parameters = array('namespace' => $namespace, 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $basename, 'extension_alias' => Container::underscore($basename));
     $this->renderFile($this->skeletonDir, 'Bundle.php', $dir . '/' . $bundle . '.php', $parameters);
     $this->renderFile($this->skeletonDir, 'Extension.php', $dir . '/DependencyInjection/' . $basename . 'Extension.php', $parameters);
     $this->renderFile($this->skeletonDir, 'Configuration.php', $dir . '/DependencyInjection/Configuration.php', $parameters);
     $this->renderFile($this->skeletonDir, 'DefaultController.php', $dir . '/Controller/DefaultController.php', $parameters);
     $this->renderFile($this->skeletonDir, 'index.html.twig', $dir . '/Resources/views/Default/index.html.twig', $parameters);
     $this->renderFile($this->skeletonDir, 'services.xml', $dir . '/Resources/config/services.xml', $parameters);
     if ($structure) {
         $this->filesystem->mkdir($dir . '/Resources/doc');
         $this->filesystem->touch($dir . '/Resources/doc/index.rst');
         $this->filesystem->mkdir($dir . '/Resources/translations');
         $this->filesystem->copy($this->skeletonDir . '/messages.fr.yml', $dir . '/Resources/translations/messages.fr.yml');
         $this->filesystem->mkdir($dir . '/Resources/public/css');
         $this->filesystem->mkdir($dir . '/Resources/public/images');
         $this->filesystem->mkdir($dir . '/Resources/public/js');
         $this->filesystem->mkdir($dir . '/Tests');
         $this->filesystem->mkdir($dir . '/Tests/Controller');
         $this->filesystem->mkdir($dir . '/Tests/Entity');
         $target = $dir . '/Resources/doc/index.md';
         $this->renderFile($this->skeletonDir, 'index.md', $target, array('creationdate' => date("d/m/Y"), 'author' => 'Lowbi', 'bundleName' => $bundle));
     }
 }
开发者ID:r4cker,项目名称:lowbi,代码行数:29,代码来源:SensoBundleGenerator.php

示例3: addResource

 /**
  * Adds a routing resource at the top of the existing ones.
  *
  * @param string $bundle
  * @param string $format
  * @param string $prefix
  * @param string $path
  *
  * @return Boolean true if it worked, false otherwise
  *
  * @throws \RuntimeException If bundle is already imported
  */
 public function addResource($bundle, $format, $prefix = null, $path = 'routing')
 {
     $current = '';
     if (null === $prefix) {
         $prefix = '/admin/' . Container::underscore($bundle) . ($this->yaml_prefix ? '/' . $this->yaml_prefix : '');
     }
     $routing_name = $bundle . ('/' !== $prefix ? '_' . str_replace('/', '_', substr($prefix, 1)) : '');
     if (file_exists($this->file)) {
         $current = file_get_contents($this->file);
         // Don't add same bundle twice
         if (false !== strpos($current, $routing_name)) {
             throw new \RuntimeException(sprintf('Bundle "%s" is already imported.', $bundle));
         }
     } elseif (!is_dir($dir = dirname(realpath($this->file)))) {
         mkdir($dir, 0777, true);
     }
     $code = sprintf("%s:\n", $routing_name);
     if ('admingenerator' == $format) {
         $code .= sprintf("    resource: \"@%s/Controller/%s\"\n    type:     admingenerator\n", $bundle, $this->yaml_prefix ? ucfirst($this->yaml_prefix) . '/' : '');
     } else {
         $code .= sprintf("    resource: \"@%s/Resources/config/%s.%s\"\n", $bundle, $path, $format);
     }
     $code .= sprintf("    prefix:   %s\n", $prefix);
     $code .= "\n";
     $code .= $current;
     if (false === file_put_contents($this->file, $code)) {
         return false;
     }
     return true;
 }
开发者ID:Restless-ET,项目名称:GeneratorBundle,代码行数:42,代码来源:RoutingManipulator.php

示例4: getContainerExtension

    /**
     * Returns the bundle's container extension.
     *
     * @return ExtensionInterface|null The container extension
     *
     * @api
     */
    public function getContainerExtension()
    {
        if (null === $this->extension) {
            $basename = preg_replace('/Bundle$/', '', $this->getName());

            $class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
            if (class_exists($class)) {
                $extension = new $class();

                // check naming convention
                $expectedAlias = Container::underscore($basename);
                if ($expectedAlias != $extension->getAlias()) {
                    throw new \LogicException(sprintf(
                        'The extension alias for the default extension of a '.
                        'bundle must be the underscored version of the '.
                        'bundle name ("%s" instead of "%s")',
                        $expectedAlias, $extension->getAlias()
                    ));
                }

                $this->extension = $extension;
            } else {
                $this->extension = false;
            }
        }

        if ($this->extension) {
            return $this->extension;
        }
    }
开发者ID:nhp,项目名称:shopware-4,代码行数:37,代码来源:Bundle.php

示例5: getContainerExtension

    /**
     * Returns the bundle's container extension.
     *
     * @return ExtensionInterface|null The container extension
     *
     * @throws \LogicException
     */
    public function getContainerExtension()
    {
        if (null === $this->extension) {
            $extension = $this->createContainerExtension();

            if (null !== $extension) {
                if (!$extension instanceof ExtensionInterface) {
                    throw new \LogicException(sprintf('Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_class($extension)));
                }

                // check naming convention
                $basename = preg_replace('/Bundle$/', '', $this->getName());
                $expectedAlias = Container::underscore($basename);

                if ($expectedAlias != $extension->getAlias()) {
                    throw new \LogicException(sprintf(
                        'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.',
                        $expectedAlias, $extension->getAlias()
                    ));
                }

                $this->extension = $extension;
            } else {
                $this->extension = false;
            }
        }

        if ($this->extension) {
            return $this->extension;
        }
    }
开发者ID:symfony,项目名称:symfony,代码行数:38,代码来源:Bundle.php

示例6: generateExt

 /**
  * {@inheritdoc}
  */
 public function generateExt($namespace, $bundle, $dir, $format, $structure, array $options)
 {
     $format = 'annotation';
     // @codeCoverageIgnoreStart
     if (null === $this->bundleSkeletonDir) {
         $this->bundleSkeletonDir = __DIR__ . '/../../../../../../vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton';
         if (!file_exists($this->bundleSkeletonDir)) {
             $this->bundleSkeletonDir = __DIR__ . '/../../../../../../../sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton';
         }
     }
     // @codeCoverageIgnoreEnd
     $this->setSkeletonDirs($this->bundleSkeletonDir);
     $this->generate($namespace, $bundle, $dir, $format, $structure);
     $dir .= '/' . strtr($namespace, '\\', '/');
     $themeBasename = str_replace('Bundle', '', $bundle);
     $extensionAlias = Container::underscore($themeBasename);
     $themeSkeletonDir = __DIR__ . '/../../Resources/skeleton/app-theme';
     $this->setSkeletonDirs($themeSkeletonDir);
     $parameters = array('namespace_path' => str_replace('\\', '\\\\', $namespace), 'target_dir' => str_replace('\\', '/', $namespace), 'bundle' => $bundle, 'theme_basename' => $themeBasename, 'extension_alias' => $extensionAlias);
     $this->renderFile('theme.xml', $dir . '/Resources/config/' . $extensionAlias . '.xml', $parameters);
     $this->renderFile('info.yml', $dir . '/Resources/data/info.yml', $parameters);
     $this->renderFile('autoload.json', $dir . '/autoload.json', $parameters);
     $this->renderFile('composer.json', $dir . '/composer.json', $parameters);
     $this->filesystem->mkdir($dir . '/Resources/views/Theme');
     $this->filesystem->mkdir($dir . '/Resources/views/Slots');
 }
开发者ID:iicc,项目名称:RedKiteCmsBundle,代码行数:29,代码来源:AppThemeGenerator.php

示例7: generateExt

 /**
  * {@inheritdoc}
  */
 public function generateExt($namespace, $bundle, $dir, $format, $structure, array $options)
 {
     $format = 'annotation';
     // @codeCoverageIgnoreStart
     if (null === $this->bundleSkeletonDir) {
         $this->bundleSkeletonDir = __DIR__ . '/../../../../../../vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton';
         if (!file_exists($this->bundleSkeletonDir)) {
             $this->bundleSkeletonDir = __DIR__ . '/../../../../../../../sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton';
         }
     }
     // @codeCoverageIgnoreEnd
     $this->setSkeletonDirs($this->bundleSkeletonDir);
     $this->generate($namespace, $bundle, $dir, $format, $structure);
     $dir .= '/' . strtr($namespace, '\\', '/');
     $bundleBasename = str_replace('Bundle', '', $bundle);
     $this->filesystem->mkdir($dir . '/Core/Block');
     $extensionAlias = Container::underscore($bundleBasename);
     $typeLowercase = strtolower($bundleBasename);
     $parameters = array('namespace' => $namespace, 'namespace_path' => str_replace('\\', '\\\\', $namespace), 'target_dir' => str_replace('\\', '/', $namespace), 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $bundleBasename, 'type_lowercase' => $typeLowercase, 'extension_alias' => $extensionAlias, 'description' => $options["description"], 'group' => $options["group"]);
     $blockSkeletonDir = __DIR__ . '/../../Resources/skeleton/app-block';
     $this->setSkeletonDirs($blockSkeletonDir);
     $this->renderFile('Block.php', $dir . '/Core/Block/BlockManager' . $bundleBasename . '.php', $parameters);
     $this->renderFile('FormType.php', $dir . '/Core/Form/' . $bundleBasename . 'Type.php', $parameters);
     $this->renderFile('app_block.xml', $dir . '/Resources/config/app_block.xml', $parameters);
     $this->renderFile('config_rkcms.yml', $dir . '/Resources/config/config_rkcms.yml', $parameters);
     $this->renderFile('config_rkcms_dev.yml', $dir . '/Resources/config/config_rkcms_dev.yml', $parameters);
     $this->renderFile('config_rkcms_test.yml', $dir . '/Resources/config/config_rkcms_test.yml', $parameters);
     $this->renderFile('autoload.json', $dir . '/autoload.json', $parameters);
     if (!array_key_exists("no-strict", $options) || $options["no-strict"] == false) {
         $this->renderFile('composer.json', $dir . '/composer.json', $parameters);
     }
     $this->filesystem->copy($blockSkeletonDir . '/block.html.twig', $dir . '/Resources/views/Content/' . $typeLowercase . '.html.twig');
     $this->filesystem->copy($blockSkeletonDir . '/form_editor.html.twig', $dir . '/Resources/views/Editor/' . $typeLowercase . '.html.twig');
 }
开发者ID:iicc,项目名称:RedKiteCmsBundle,代码行数:37,代码来源:AppBlockGenerator.php

示例8: addResource

 /**
  * Adds a routing resource at the top of the existing ones.
  *
  * @param string $bundle
  * @param string $format
  * @param string $prefix
  * @param string $path
  *
  * @return bool true if it worked, false otherwise
  *
  * @throws \RuntimeException If bundle is already imported
  */
 public function addResource($bundle, $format, $prefix = '/', $path = 'routing')
 {
     $current = '';
     if (file_exists($this->file)) {
         $current = file_get_contents($this->file);
         // Don't add same bundle twice
         if (false !== strpos($current, $bundle)) {
             throw new \RuntimeException(sprintf('Bundle "%s" is already imported.', $bundle));
         }
     } elseif (!is_dir($dir = dirname($this->file))) {
         mkdir($dir, 0777, true);
     }
     $bundleName = substr($bundle, 0, -6);
     $prefixName = '/' !== $prefix ? '_' . str_replace('/', '_', substr($prefix, 1)) : '';
     $prefixName = strpos($bundleName, $prefixName) !== false ? $prefixName : '';
     $code = sprintf("%s:\n", Container::underscore($bundleName) . $prefixName);
     if ('annotation' == $format) {
         $code .= sprintf("    resource: \"@%s/Controller/\"\n    type:     annotation\n", $bundle);
     } else {
         $code .= sprintf("    resource: \"@%s/Resources/config/%s.%s\"\n", $bundle, $path, $format);
     }
     $code .= sprintf("    prefix:   %s\n", $prefix);
     $code .= "\n";
     $code .= $current;
     if (false === file_put_contents($this->file, $code)) {
         return false;
     }
     return true;
 }
开发者ID:sulu,项目名称:sulu,代码行数:41,代码来源:RoutingManipulator.php

示例9: generate

 public function generate($namespace, $bundle, $dir, $format, $structure)
 {
     $dir .= '/' . strtr($namespace, '\\', '/');
     if (file_exists($dir)) {
         throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.', realpath($dir)));
     }
     $basename = substr($bundle, 0, -6);
     $parameters = array('namespace' => $namespace, 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $basename, 'extension_alias' => Container::underscore($basename));
     $this->renderFile($this->skeletonDir, 'Bundle.php', $dir . '/' . $bundle . '.php', $parameters);
     $this->renderFile($this->skeletonDir, 'Extension.php', $dir . '/DependencyInjection/' . $basename . 'Extension.php', $parameters);
     $this->renderFile($this->skeletonDir, 'Configuration.php', $dir . '/DependencyInjection/Configuration.php', $parameters);
     $this->renderFile($this->skeletonDir, 'DefaultController.php', $dir . '/Controller/DefaultController.php', $parameters);
     $this->renderFile($this->skeletonDir, 'DefaultControllerTest.php', $dir . '/Tests/Controller/DefaultControllerTest.php', $parameters);
     $this->renderFile($this->skeletonDir, 'index.html.twig', $dir . '/Resources/views/Default/index.html.twig', $parameters);
     if ('xml' === $format || 'annotation' === $format) {
         $this->renderFile($this->skeletonDir, 'services.xml', $dir . '/Resources/config/services.xml', $parameters);
     } else {
         $this->renderFile($this->skeletonDir, 'services.' . $format, $dir . '/Resources/config/services.' . $format, $parameters);
     }
     if ('annotation' != $format) {
         $this->renderFile($this->skeletonDir, 'routing.' . $format, $dir . '/Resources/config/routing.' . $format, $parameters);
     }
     if ($structure) {
         $this->filesystem->mkdir($dir . '/Resources/doc');
         $this->filesystem->touch($dir . '/Resources/doc/index.rst');
         $this->filesystem->mkdir($dir . '/Resources/translations');
         $this->filesystem->copy($this->skeletonDir . '/messages.fr.xliff', $dir . '/Resources/translations/messages.fr.xliff');
         $this->filesystem->mkdir($dir . '/Resources/public/css');
         $this->filesystem->mkdir($dir . '/Resources/public/images');
         $this->filesystem->mkdir($dir . '/Resources/public/js');
     }
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:32,代码来源:BundleGenerator.php

示例10: generateServiceNameFromClassName

 /**
  * Convert a class name to a standardized symfony service name
  *   'Acme\FooBundle\Bar\FooBar' => 'acme.foo_bundle.bar.foo_bar'
  * @param $classname
  * @return string
  */
 public function generateServiceNameFromClassName($classname)
 {
     $classname = str_replace(['\\', '_'], '.', $classname);
     // @todo in Core-2.0 the '_' can be removed.
     $classname = Container::underscore($classname);
     return trim($classname, "\\_. \t\n\r\v");
 }
开发者ID:Silwereth,项目名称:core,代码行数:13,代码来源:ServiceNameHelper.php

示例11: generate

 public function generate($namespace, $bundle, $dir, $format, $structure)
 {
     $dir .= '/' . strtr($namespace, '\\', '/');
     if (file_exists($dir)) {
         if (!is_dir($dir)) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" exists but is a file.', realpath($dir)));
         }
         $files = scandir($dir);
         if ($files != array('.', '..')) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.', realpath($dir)));
         }
         if (!is_writable($dir)) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not writable.', realpath($dir)));
         }
     }
     $basename = substr($bundle, 0, -6);
     $parameters = array('namespace' => $namespace, 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $basename, 'extension_alias' => Container::underscore($basename));
     $this->renderFile('bundle/Bundle.php.twig', $dir . '/' . $bundle . '.php', $parameters);
     $this->renderFile('bundle/Controller.php.twig', $dir . '/Controller/' . $basename . 'Controller.php', $parameters);
     $this->renderFile('bundle/Entity.php.twig', $dir . '/Entity/' . $basename . '.php', $parameters);
     $this->renderFile('bundle/ControllerTest.php.twig', $dir . '/Tests/Controller/' . $basename . 'ControllerTest.php', $parameters);
     if ('xml' === $format || 'annotation' === $format) {
         $this->renderFile('bundle/services.xml.twig', $dir . '/Resources/config/services.xml', $parameters);
     } else {
         $this->renderFile('bundle/services.' . $format . '.twig', $dir . '/Resources/config/services.' . $format, $parameters);
     }
     if ('annotation' != $format) {
         $this->renderFile('bundle/routing.' . $format . '.twig', $dir . '/Resources/config/routing.' . $format, $parameters);
     }
 }
开发者ID:web-ant,项目名称:webant-corebundle,代码行数:30,代码来源:BundleGenerator.php

示例12: generate

 /**
  * generate bundle code
  *
  * @param string $namespace namspace name
  * @param string $bundle    bundle name
  * @param string $dir       bundle dir
  * @param string $format    bundle condfig file format
  *
  * @return void
  */
 public function generate($namespace, $bundle, $dir, $format)
 {
     $dir .= '/' . strtr($namespace, '\\', '/');
     if (file_exists($dir)) {
         if (!is_dir($dir)) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" exists but is a file.', realpath($dir)));
         }
         $files = scandir($dir);
         if ($files != array('.', '..')) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.', realpath($dir)));
         }
         if (!is_writable($dir)) {
             throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not writable.', realpath($dir)));
         }
     }
     $basename = $this->getBundleBaseName($bundle);
     $parameters = array('namespace' => $namespace, 'bundle' => $bundle, 'format' => $format, 'bundle_basename' => $basename, 'extension_alias' => Container::underscore($basename));
     $this->renderFile('bundle/Bundle.php.twig', $dir . '/' . $bundle . '.php', $parameters);
     $this->renderFile('bundle/Extension.php.twig', $dir . '/DependencyInjection/' . $basename . 'Extension.php', $parameters);
     if ('xml' === $format || 'annotation' === $format) {
         // @todo make this leave doctrine alone and move doctrine to a Manipulator in generate:resource
         $this->renderFile('bundle/services.xml.twig', $dir . '/Resources/config/services.xml', $parameters);
         mkdir($dir . '/Resources/config/doctrine');
         $this->renderFile('bundle/config.xml.twig', $dir . '/Resources/config/config.xml', $parameters);
     } else {
         $this->renderFile('bundle/services.' . $format . '.twig', $dir . '/Resources/config/services.' . $format, $parameters);
         mkdir($dir . '/Resources/config/doctrine');
         $this->renderFile('bundle/config.' . $format . '.twig', $dir . '/Resources/config/config.' . $format, $parameters);
     }
     if ('annotation' != $format) {
         $this->renderFile('bundle/routing.' . $format . '.twig', $dir . '/Resources/config/routing.' . $format, $parameters);
     }
 }
开发者ID:alebon,项目名称:graviton,代码行数:43,代码来源:BundleGenerator.php

示例13: getAlias

 /**
  * Returns the recommended alias to use in XML.
  *
  * This alias is also the mandatory prefix to use when using YAML.
  *
  * @return string The alias
  */
 public function getAlias()
 {
     $className = get_class($this);
     if (substr($className, -9) != 'Extension') {
         throw new \BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
     }
     $classBaseName = substr(strrchr($className, '\\'), 1, -9);
     return Container::underscore($classBaseName);
 }
开发者ID:norwayapp,项目名称:Invest,代码行数:16,代码来源:Extension.php

示例14: getShortNameForBundle

 private function getShortNameForBundle($bundleName)
 {
     $shortName = $bundleName;
     if (mb_substr($bundleName, -6) === 'Bundle') {
         $shortName = mb_substr($shortName, 0, -6);
     }
     // this is used by SensioGenerator bundle when generating extension name from bundle name
     return Container::underscore($shortName);
 }
开发者ID:mariusbalcytis,项目名称:webpack-bundle,代码行数:9,代码来源:AliasManager.php

示例15: process

 /**
  * @see \Symfony\Component\HttpKernel\Bundle::registerCommands
  *
  * @param ContainerBuilder $container
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasParameter('bangpound_console.default_application_id')) {
         return;
     }
     $count = 0;
     $defaultApplicationId = $container->getParameter('bangpound_console.default_application_id');
     // Identify classes of already tagged Command services
     // so this pass does not create additional service definitions
     // for them.
     $classes = array_map(function ($id) use($container) {
         $class = $container->getDefinition($id)->getClass();
         return $container->getParameterBag()->resolveValue($class);
     }, array_keys($container->findTaggedServiceIds('console.command')));
     /** @var BundleInterface $bundle */
     foreach ($this->bundles as $bundle) {
         if (!is_dir($dir = $bundle->getPath() . '/Command')) {
             continue;
         }
         $finder = new Finder();
         $finder->files()->name('*Command.php')->in($dir);
         $prefix = $bundle->getNamespace() . '\\Command';
         /** @var SplFileInfo $file */
         foreach ($finder as $file) {
             $ns = $prefix;
             if ($relativePath = $file->getRelativePath()) {
                 $ns .= '\\' . strtr($relativePath, '/', '\\');
             }
             $class = $ns . '\\' . $file->getBasename('.php');
             // This command is already in the container.
             if (in_array($class, $classes)) {
                 continue;
             }
             $r = new \ReflectionClass($class);
             if ($r->isSubclassOf(self::COMMAND_CLASS) && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
                 $name = Container::underscore(preg_replace('/Command/', '', $r->getShortName()));
                 $name = strtolower(str_replace('\\', '_', $name));
                 if (!$bundle->getContainerExtension()) {
                     $alias = preg_replace('/Bundle$/', '', $bundle->getName());
                     $alias = Container::underscore($alias);
                 } else {
                     $alias = $bundle->getContainerExtension()->getAlias();
                 }
                 $id = $alias . '.command.' . $name;
                 if ($container->hasDefinition($id)) {
                     $id = sprintf('%s_%d', hash('sha256', $file), ++$count);
                 }
                 $definition = $container->register($id, $r->getName());
                 $definition->addTag('console.command', ['application' => $defaultApplicationId]);
                 if ($r->isSubclassOf('Symfony\\Component\\DependencyInjection\\ContainerAwareInterface')) {
                     $definition->addMethodCall('setContainer', [new Reference('service_container')]);
                 }
             }
         }
     }
 }
开发者ID:bangpound,项目名称:console-bundle,代码行数:61,代码来源:AutoAddConsoleCommandPass.php


注:本文中的Symfony\Component\DependencyInjection\Container::underscore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。