/**
  * Gets translation files location.
  *
  * @return array
  */
 private function getLocations()
 {
     $locations = array();
     if (class_exists('Symfony\\Component\\Validator\\Validator')) {
         $r = new \ReflectionClass('Symfony\\Component\\Validator\\Validator');
         $locations[] = dirname($r->getFilename()) . '/Resources/translations';
     }
     if (class_exists('Symfony\\Component\\Form\\Form')) {
         $r = new \ReflectionClass('Symfony\\Component\\Form\\Form');
         $locations[] = dirname($r->getFilename()) . '/Resources/translations';
     }
     if (class_exists('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException')) {
         $r = new \ReflectionClass('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException');
         if (file_exists($dir = dirname($r->getFilename()) . '/../../Resources/translations')) {
             $locations[] = $dir;
         } else {
             // Symfony 2.4 and above
             $locations[] = dirname($r->getFilename()) . '/../Resources/translations';
         }
     }
     $overridePath = $this->kernel->getRootDir() . '/Resources/%s/translations';
     foreach ($this->kernel->getBundles() as $bundle => $class) {
         $reflection = new \ReflectionClass($class);
         if (is_dir($dir = dirname($reflection->getFilename()) . '/Resources/translations')) {
             $locations[] = $dir;
         }
         if (is_dir($dir = sprintf($overridePath, $bundle))) {
             $locations[] = $dir;
         }
     }
     if (is_dir($dir = $this->kernel->getRootDir() . '/Resources/translations')) {
         $locations[] = $dir;
     }
     return $locations;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $noInitialize = $input->getOption('no-initialize');
     $append = $input->getOption('append');
     if ($input->isInteractive() && !$append) {
         $dialog = $this->getHelperSet()->get('dialog');
         $confirmed = $dialog->askConfirmation($output, '<question>Careful, database will be purged. Do you want to continue Y/N ?</question>', false);
         if (!$confirmed) {
             return 0;
         }
     }
     $paths = $input->getOption('fixtures');
     $candidatePaths = [];
     if (!$paths) {
         $paths = [];
         foreach ($this->kernel->getBundles() as $bundle) {
             $candidatePath = $bundle->getPath() . '/DataFixtures/Document';
             $candidatePaths[] = $candidatePath;
             if (file_exists($candidatePath)) {
                 $paths[] = $candidatePath;
             }
         }
     }
     if (empty($paths)) {
         $output->writeln('<info>Could not find any candidate fixture paths.</info>');
         if ($input->getOption('verbose')) {
             $output->writeln(sprintf('Looked for: </comment>%s<comment>"</comment>', implode('"<comment>", "</comment>', $candidatePaths)));
         }
         return 0;
     }
     $fixtures = $this->loader->load($paths);
     $this->executor->execute($fixtures, false === $append, false === $noInitialize, $output);
     $output->writeln('');
     $output->writeln(sprintf('<info>Done. Executed </info>%s</info><info> fixtures.</info>', count($fixtures)));
 }
示例#3
0
 /**
  * @return array
  */
 public function getConfigurations()
 {
     if ($this->configuration !== null) {
         return $this->configuration;
     }
     $bundles = $this->kernel->getBundles();
     $configuration = [];
     foreach ($bundles as $bundle) {
         try {
             $class = get_class($bundle);
             $classParts = explode('\\', $class);
             $bundleName = array_pop($classParts);
             $file = $this->kernel->locateResource(sprintf('@%s/Resources/config/search.yml', $bundleName));
         } catch (\Exception $e) {
             continue;
         }
         $data = $this->parseFile($file);
         if (is_array($data)) {
             foreach ($data as $class => $config) {
                 $configuration[$class] = $config;
             }
         }
     }
     $this->configuration = $configuration;
     return $configuration;
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $this->data = array('app_name' => $this->name, 'app_version' => $this->version, 'token' => $response->headers->get('X-Debug-Token'), 'symfony_version' => Kernel::VERSION, 'symfony_state' => 'unknown', 'name' => isset($this->kernel) ? $this->kernel->getName() : 'n/a', 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a', 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a', 'php_version' => PHP_VERSION, 'xdebug_enabled' => extension_loaded('xdebug'), 'eaccel_enabled' => extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'), 'apc_enabled' => extension_loaded('apc') && ini_get('apc.enabled'), 'xcache_enabled' => extension_loaded('xcache') && ini_get('xcache.cacher'), 'wincache_enabled' => extension_loaded('wincache') && ini_get('wincache.ocenabled'), 'zend_opcache_enabled' => extension_loaded('Zend OPcache') && ini_get('opcache.enable'), 'bundles' => array(), 'sapi_name' => PHP_SAPI);
     if (isset($this->kernel)) {
         foreach ($this->kernel->getBundles() as $name => $bundle) {
             $this->data['bundles'][$name] = $bundle->getPath();
         }
         $this->data['symfony_state'] = $this->determineSymfonyState();
     }
 }
 /**
  * Returns the Bundle instance in which the given class name is located.
  *
  * @param string $class A fully qualified controller class name
  * @param Bundle $bundle A Bundle instance
  * @throws \InvalidArgumentException
  */
 protected function getBundleForClass($class)
 {
     $namespace = strtr(dirname(strtr($class, '\\', '/')), '/', '\\');
     foreach ($this->kernel->getBundles() as $bundle) {
         if (0 === strpos($namespace, $bundle->getNamespace())) {
             return $bundle;
         }
     }
     throw new \InvalidArgumentException(sprintf('The "%s" class does not belong to a registered bundle.', $class));
 }
 /**
  * {@inheritdoc}
  */
 public function installAssets($targetDir, $symlinkMask)
 {
     // Create the bundles directory otherwise symlink will fail.
     $targetDir = rtrim($targetDir, '/') . '/bundles/';
     $this->filesystem->mkdir($targetDir);
     $effectiveSymlinkMask = $symlinkMask;
     foreach ($this->kernel->getBundles() as $bundle) {
         $effectiveSymlinkMask = min($effectiveSymlinkMask, $this->installBundleAssets($bundle, $targetDir, $symlinkMask));
     }
     return $effectiveSymlinkMask;
 }
 public function process(ContainerBuilder $container)
 {
     if (!$container->has('ezpublish_legacy.legacy_bundles.extension_locator')) {
         return;
     }
     $locator = $container->get('ezpublish_legacy.legacy_bundles.extension_locator');
     $extensionNames = array();
     foreach ($this->kernel->getBundles() as $bundle) {
         $extensionNames += array_flip($locator->getExtensionNames($bundle));
     }
     $container->setParameter('ezpublish_legacy.legacy_bundles_extensions', array_keys($extensionNames));
 }
 /**
  * Returns paths to directories that *might* contain Twig views.
  *
  * Please note, that it is not guaranteed that these directories exist.
  *
  * @return string[]
  */
 protected function getPossibleViewDirectories()
 {
     $viewDirectories = array();
     $globalResourceDirectory = $this->kernel->getRootDir() . '/Resources';
     $viewDirectories[] = $globalResourceDirectory;
     foreach ($this->kernel->getBundles() as $bundle) {
         /* @var $bundle BundleInterface */
         $viewDirectory = $bundle->getPath() . '/Resources/views';
         $viewDirectories[] = $viewDirectory;
     }
     return $viewDirectories;
 }
示例#9
0
 /**
  * {@inheritdoc}
  */
 public function getBundles()
 {
     $bundles = $this->kernel->getBundles();
     if (!empty($this->excludeBundleNames)) {
         foreach ($bundles as $key => $bundle) {
             if (in_array($bundle->getName(), $this->excludeBundleNames)) {
                 unset($bundles[$key]);
             }
         }
     }
     return $bundles;
 }
示例#10
0
 /**
  * Returns bundle for particular controller
  *
  * @param ReflectionClass $class
  *
  * @return \Symfony\Component\HttpKernel\Bundle\BundleInterface
  */
 protected function getBundleForClass(ReflectionClass $reflectionClass)
 {
     $bundles = $this->kernel->getBundles();
     do {
         $namespace = $reflectionClass->getNamespaceName();
         foreach ($bundles as $bundle) {
             if (0 === strpos($namespace, $bundle->getNamespace())) {
                 return $bundle;
             }
         }
         $reflectionClass = $reflectionClass->getParentClass();
     } while ($reflectionClass);
 }
 /**
  * Get correct casing of the module which is based on the bundle.
  *
  * @param  string $module
  * @return string
  */
 public function formatModule($module)
 {
     $module = strtolower($module);
     if (isset($this->moduleCache[$module])) {
         return $this->moduleCache[$module];
     }
     foreach ($this->kernel->getBundles() as $bundle) {
         if ($module . "bundle" == strtolower($bundle->getName())) {
             return $this->moduleCache[$module] = str_replace("Bundle", "", $bundle->getName());
         }
     }
     throw new \RuntimeException("Couldnt find a matching bundle for the module {$module}");
 }
 /**
  * {@inheritdoc}
  */
 protected function getResources()
 {
     $resources = [];
     foreach ($this->kernel->getBundles() as $bundle) {
         foreach ($this->relativeFilePaths as $relativeFilePath) {
             $path = $bundle->getPath() . DIRECTORY_SEPARATOR . $relativeFilePath;
             if (file_exists($path)) {
                 $resources[] = $path;
             }
         }
     }
     return $resources;
 }
示例#13
0
 protected function getBundleName($className)
 {
     $bundles = $this->kernel->getBundles();
     foreach ($bundles as $bundle) {
         $class = get_class($bundle);
         $classParts = explode('\\', $class);
         $bundleName = array_pop($classParts);
         $bundlePath = implode('\\', $classParts);
         if (strpos($className, $bundlePath) === 0) {
             return $bundleName;
         }
     }
     return null;
 }
 /**
  * @return Symfony\Component\HttpKernel\Bundle\BundleInterface[]
  */
 public function getBundles()
 {
     $bundles = $this->kernel->getBundles();
     if (true === empty($this->bundles)) {
         return $bundles;
     }
     $return = [];
     foreach ($bundles as $bundle) {
         if (true === in_array($bundle->getName(), $this->bundles)) {
             $return[] = $bundle;
         }
     }
     return $return;
 }
 /**
  * Returns an array of translation files for a given domain and a given locale.
  *
  * @param string $domainName    A domain translation name.
  * @param string $locale        A locale.
  * @return array                An array of translation files.
  */
 public function getResources($domainName, $locale)
 {
     $finder = new Finder();
     $locations = array();
     foreach ($this->kernel->getBundles() as $bundle) {
         if (is_dir($bundle->getPath() . '/Resources/translations')) {
             $locations[] = $bundle->getPath() . '/Resources/translations';
         }
     }
     if (is_dir($this->kernel->getRootDir() . '/Resources/translations')) {
         $locations[] = $this->kernel->getRootDir() . '/Resources/translations';
     }
     return $finder->files()->name($domainName . '.' . $locale . '.*')->followLinks()->in($locations);
 }
 /**
  * Returns the Bundle instance in which the given class name is located.
  *
  * @param  string                    $class  A fully qualified controller class name
  * @param  Bundle                    $bundle A Bundle instance
  * @throws \InvalidArgumentException
  */
 protected function getBundleForClass($class)
 {
     $reflectionClass = new \ReflectionClass($class);
     $bundles = $this->kernel->getBundles();
     do {
         $namespace = $reflectionClass->getNamespaceName();
         foreach ($bundles as $bundle) {
             if (0 === strpos($namespace, $bundle->getNamespace())) {
                 return $bundle;
             }
         }
         $reflectionClass = $reflectionClass->getParentClass();
     } while ($reflectionClass);
     throw new \InvalidArgumentException(sprintf('The "%s" class does not belong to a registered bundle.', $class));
 }
示例#17
0
 /**
  * @return Bundle[]
  */
 private function getBundlesFromKernel(KernelInterface $kernel)
 {
     if ($bundles = $kernel->getBundles()) {
         return $bundles;
     }
     return $kernel->registerBundles();
 }
示例#18
0
文件: Jarves.php 项目: jarves/jarves
 /**
  * Loads all configurations from all registered bundles (BundleName/Resources/config/jarves*.xml)
  * @param Cacher $cacher
  *
  * @return null|callable returns a callable that should be called when config stuff have been registered
  */
 public function loadBundleConfigs(Cacher $cacher)
 {
     $cached = $cacher->getFastCache('core/configs');
     $bundles = array_keys($this->kernel->getBundles());
     $configs = new Configuration\Configs($this);
     $hashes = [];
     foreach ($bundles as $bundleName) {
         $hashes[] = $configs->getConfigHash($bundleName);
     }
     $hash = md5(implode('.', $hashes));
     if ($cached) {
         $cached = unserialize($cached);
         if (is_array($cached) && $cached['md5'] == $hash) {
             $this->configs = $cached['data'];
             $this->configs->setCore($this);
         }
     }
     if (!$this->configs) {
         $this->configs = new Configuration\Configs($this, $bundles);
         return function () use($hash, $cacher) {
             $cached = serialize(['md5' => $hash, 'data' => $this->configs]);
             $cacher->setFastCache('core/configs', $cached);
         };
     }
 }
示例#19
0
 /**
  * Register all commands from the container and bundles in the application.
  *
  * @param OutputInterface $output The output handler to use.
  *
  * @return void
  */
 protected function registerCommands(OutputInterface $output)
 {
     $container = $this->kernel->getContainer();
     foreach ($this->kernel->getBundles() as $bundle) {
         if ($bundle instanceof Bundle) {
             $bundle->registerCommands($this);
         }
     }
     if ($container->hasParameter('console.command.ids')) {
         foreach ($container->getParameter('console.command.ids') as $id) {
             $this->add($container->get($id));
         }
     }
     $this->addComposerCommands();
     /** @var ComposerJson $file */
     $file = $container->get('tenside.composer_json');
     // Add non-standard scripts as own commands - keep this last to ensure we do not override internal commands.
     if ($file->has('scripts')) {
         foreach (array_keys($file->get('scripts')) as $script) {
             if (!defined('Composer\\Script\\ScriptEvents::' . str_replace('-', '_', strtoupper($script)))) {
                 if ($this->has($script)) {
                     $output->writeln(sprintf('<warning>' . 'A script named %s would override a native function and has been skipped' . '</warning>', $script));
                     continue;
                 }
                 $this->add(new ScriptAliasCommand($script));
             }
         }
     }
 }
 /**
  * Method called at PreBindParameters event.
  *
  * @param \FSi\Component\DataSource\Event\DataSourceEvent\ParametersEventArgs $event
  */
 public function readConfiguration(DataSourceEvent\ParametersEventArgs $event)
 {
     $dataSource = $event->getDataSource();
     $dataSourceConfiguration = array();
     foreach ($this->kernel->getBundles() as $bundle) {
         if ($this->hasDataSourceConfiguration($bundle->getPath(), $dataSource->getName())) {
             $configuration = $this->getDataSourceConfiguration($bundle->getPath(), $dataSource->getName());
             if (is_array($configuration)) {
                 $dataSourceConfiguration = $configuration;
             }
         }
     }
     if (count($dataSourceConfiguration)) {
         $this->buildConfiguration($dataSource, $dataSourceConfiguration);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function readConfiguration(DataGridEventInterface $event)
 {
     $dataGrid = $event->getDataGrid();
     $dataGridConfiguration = array();
     foreach ($this->kernel->getBundles() as $bundle) {
         if ($this->hasDataGridConfiguration($bundle->getPath(), $dataGrid->getName())) {
             $configuration = $this->getDataGridConfiguration($bundle->getPath(), $dataGrid->getName());
             if (is_array($configuration)) {
                 $dataGridConfiguration = $configuration;
             }
         }
     }
     if (count($dataGridConfiguration)) {
         $this->buildConfiguration($dataGrid, $dataGridConfiguration);
     }
 }
示例#22
0
 /**
  * Constructor
  *
  * @access public
  * @param \Symfony\Component\HttpKernel\KernelInterface $kernel
  */
 public function __construct(KernelInterface $kernel = null)
 {
     $this->bundles = new \SplObjectStorage();
     if ($kernel instanceof KernelInterface) {
         $this->setBundles($kernel->getBundles());
     }
 }
示例#23
0
 /**
  * Constructor
  *
  * @param KernelInterface $kernel
  */
 public function __construct(KernelInterface $kernel)
 {
     $this->bundles = $kernel->getBundles();
     $this->appFolder = $this->realPath($kernel->getRootDir());
     $this->fileLoaders = array();
     $this->addFileLoader('php', 'Symfony\\Component\\Translation\\Loader\\PhpFileLoader');
     $this->addFileLoader('yml', 'Symfony\\Component\\Translation\\Loader\\YamlFileLoader');
     $this->addFileLoader('xlf', 'Symfony\\Component\\Translation\\Loader\\XliffFileLoader');
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContainerBuilder $container)
 {
     $resourceLocator = new FileLocator($this->kernel);
     $definition = $container->getDefinition('grid.repository');
     $configs = [];
     foreach ($this->kernel->getBundles() as $bundle) {
         try {
             $file = $resourceLocator->locate(sprintf('@%s/Resources/config/grid.yml', $bundle->getName()));
         } catch (\InvalidArgumentException $e) {
             continue;
         }
         $container->addResource(new FileResource($file));
         $grid = Yaml::parse(file_get_contents($file));
         $config = $this->processConfiguration($grid);
         $this->setGridDefinition($definition, $config);
     }
     $container->setParameter('grid.definitions', $configs);
 }
示例#25
0
文件: Import.php 项目: Silwereth/sulu
 /**
  * Executes the import. All translations found in the bundles get imported.
  *
  * @param bool $backend  True to import the backend file
  * @param bool $frontend True to import the frontend file
  */
 public function executeFromBundles($backend = true, $frontend = true)
 {
     foreach ($this->kernel->getBundles() as $bundle) {
         // access bundle path directly to ignore bundle inheritance
         $pathToTranslations = $bundle->getPath() . '/' . $this->path;
         if (is_dir($pathToTranslations)) {
             $this->importBundle($bundle, $pathToTranslations, $backend, $frontend);
         }
     }
 }
 /**
  * Construct method
  *
  * @param KernelInterface $kernel          Kernel instance
  * @param Reader          $reader          Reader
  * @param Finder          $finder          Finder
  * @param array           $bundles         Bundle array where to parse workers, defined on condiguration
  * @param array           $servers         Server list defined on configuration
  * @param array           $defaultSettings Default settings defined on configuration
  */
 public function __construct(KernelInterface $kernel, Reader $reader, Finder $finder, array $bundles, array $servers, array $defaultSettings)
 {
     $this->kernelBundles = $kernel->getBundles();
     $this->kernel = $kernel;
     $this->reader = $reader;
     $this->finder = $finder;
     $this->bundles = $bundles;
     $this->servers = $servers;
     $this->defaultSettings = $defaultSettings;
 }
 /**
  * @param ContainerBuilder $container
  * @return array
  * @throws \Exception
  */
 private function getBundleFiles(ContainerBuilder $container)
 {
     $config = $container->getParameter('voryx_thruway');
     $scanBundles = $config['locations']['bundles'];
     $bundles = $this->kernel->getBundles();
     $files = [];
     foreach ($bundles as $name => $bundle) {
         if (!in_array($name, $scanBundles, true)) {
             continue;
         }
         $finder = new Finder();
         $finder->files()->in($bundle->getPath())->name('*.php')->contains('Voryx\\ThruwayBundle\\Annotation')->depth('< 5');
         /* @var $file \Symfony\Component\Finder\SplFileInfo */
         foreach ($finder as $file) {
             $files[] = $this->getClassName($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename());
         }
     }
     return $files;
 }
示例#28
0
 public function __construct(DocParser $docParser, KernelInterface $kernel)
 {
     $this->docParser = $docParser;
     $bundles = $kernel->getBundles();
     foreach ($bundles as $bundle) {
         $this->bundles[$bundle->getNamespace()] = $bundle->getName();
     }
     $this->traverser = new \PHPParser_NodeTraverser();
     $this->traverser->addVisitor($this);
 }
示例#29
0
 /**
  * Load templates
  *
  * @return array Templates found
  *
  * @throws ConfigurationParameterNotFoundException Parameter not found
  * @throws Exception                               ConfigurationBundle not installed
  */
 public function loadTemplates()
 {
     if (!$this->configurationManager instanceof ConfigurationManager) {
         throw new Exception('You need to install ConfigurationBundle');
     }
     $templates = new ArrayCollection([]);
     $bundles = $this->kernel->getBundles();
     /**
      * @var Bundle $bundle
      */
     foreach ($bundles as $bundle) {
         if ($bundle instanceof TemplateInterface) {
             $bundleName = $bundle->getName();
             $bundleNamespace = $bundle->getNamespace();
             $templates->set($bundleName, ['bundle' => $bundleName, 'namespace' => $bundleNamespace, 'name' => $bundle->getTemplateName()]);
         }
     }
     $templatesArray = $templates->toArray();
     $this->configurationManager->set('store.templates', $templatesArray);
     return $templatesArray;
 }
示例#30
0
 /**
  * Load installed plugin bundles and return an array with them, indexed by
  * their namespaces
  *
  * @return \Symfony\Component\HttpKernel\Bundle\Bundle[] Plugins installed
  */
 protected function getInstalledPluginBundles(\Symfony\Component\HttpKernel\KernelInterface $kernel)
 {
     $plugins = [];
     $bundles = $kernel->getBundles();
     foreach ($bundles as $bundle) {
         if ($bundle instanceof \Symfony\Component\HttpKernel\Bundle\Bundle && $bundle instanceof \Elcodi\Component\Plugin\Interfaces\PluginInterface) {
             $pluginNamespace = $bundle->getNamespace();
             $plugins[$pluginNamespace] = $bundle;
         }
     }
     return $plugins;
 }