/** * {@inheritdoc} */ public function locate($resource, GeneratorInterface $generator) { $bundles = $this->kernel->getBundles(); $class = get_class($generator); $appResources = $this->kernel->getContainer()->getParameter('kernel.root_dir') . '/Resources/'; $location = "skeleton/{$generator->getName()}/{$resource}"; /** @var Bundle $bundle */ foreach ($bundles as $bundle) { if (strpos($class, $bundle->getNamespace()) !== false) { $global = "{$appResources}/{$bundle->getName()}/{$location}"; if (file_exists($global) && is_readable($global)) { return $global; } else { $local = "{$bundle->getPath()}/Resources/{$location}"; if (file_exists($local) && is_readable($local)) { return $local; } else { throw new ResourceNotFoundException("Resource {$resource} could not be located for generator {$generator->getName()}"); } } } } $nonBundle = "{$appResources}{$location}"; if (file_exists($nonBundle) && is_readable($nonBundle)) { return $nonBundle; } throw new ResourceNotFoundException("Resource {$resource} could not be located for generator {$generator->getName()}"); }
/** * @author Krzysztof Bednarczyk * @return string[] */ public function findWebsocketClasses() { $dirs = array(); foreach ($this->kernel->getBundles() as $bundle) { if (in_array($bundle->getName(), $this->blackListedBundles)) { continue; } if (!is_dir($websocketDir = $bundle->getPath() . '/Websocket')) { continue; } $dirs[] = $websocketDir; } foreach (Finder::create()->name('*Websocket.php')->in($dirs)->files() as $file) { $filename = $file->getRealPath(); if (!in_array($filename, $this->blackListedWebsocketFiles)) { require_once $filename; } } // It is not so important if these controllers never can be reached with // the current configuration nor whether they are actually controllers. // Important is only that we do not miss any classes. return array_filter(get_declared_classes(), function ($name) { return preg_match('/Websocket\\\\(.+)Websocket$/', $name) > 0; }); }
/** * @param null $filter * @return array|BundleInterface[] */ public function getBundles($filter = null) { $bundles = $this->kernel->getBundles(); $filterFunction = function (Bundle $bundle) use($filter) { return strpos($bundle->getName(), $filter) !== false; }; if (!$filter) { return $bundles; } else { return array_filter($bundles, $filterFunction); } }
/** * Read scripts info from files */ protected function loadScripts() { $index = 0; $scripts = []; $this->scripts = []; $rootDir = realpath($this->kernel->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); $bundles = $this->kernel->getBundles(); foreach ($bundles as $bundle) { $bundleDirName = $bundle->getPath(); $this->getScriptInfo($bundleDirName, $index, $scripts); $relativePathArray = explode(DIRECTORY_SEPARATOR, str_replace($rootDir, '', $bundleDirName)); if ($relativePathArray[0] == '') { unset($relativePathArray[0]); } for ($i = count($relativePathArray); $i >= 0; $i--) { unset($relativePathArray[$i]); $checkPath = $rootDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $relativePathArray); if ($this->getScriptInfo($checkPath, $index, $scripts)) { break; } } } if (!empty($scripts)) { usort($scripts, array($this, "compareScripts")); foreach ($scripts as $script) { $this->scripts[$script['key']] = $script; } } }
/** * Load the generators confirming to default naming rules in all bundles in the given Kernel. * @param Kernel $kernel */ public function loadBundleGenerators(Kernel $kernel) { /** @var Bundle $bundle */ foreach ($kernel->getBundles() as $bundle) { $this->loadGeneratorsForBundle($bundle); } }
/** * Converti les fichiers de traductions "Symfony2 style" vers les fichiers "Bigfoot style" * * @param array $bundles * @param ProgressBar $progress */ public function symfony2ToBigFoot(array $bundles = array(), $progress = null) { $newTranslationFiles = array(); $bundles = count($bundles) == 0 ? $this->kernel->getBundles() : $bundles; foreach ($bundles as $bundle) { $translationsPath = $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations'; $translationFiles = array(); $this->findTranslationFiles($translationsPath, $translationFiles); foreach ($translationFiles as $translationFile) { $pathinfo = pathinfo($translationFile); $domain = substr($pathinfo['filename'], 0, strrpos($pathinfo['filename'], '.')); $lang = substr($pathinfo['filename'], strrpos($pathinfo['filename'], '.') + 1); $parsedTranslations = array(); $translations = Yaml::parse(file_get_contents($translationFile)); // les clefs qui ont au moins 3 niveaux (par exemple foo.bar.baz) sont gérées dans un fichier foo.bar.yml // les clefs qui ont moins de 3 niveaux sont gérées dans default.yml foreach ($translations as $key1 => $translation1) { if (is_array($translation1)) { foreach ($translation1 as $key2 => $translation2) { $fileName = $this->getTranslationKey($key1, $key2) . '.yml'; if (array_key_exists($fileName, $newTranslationFiles) == false) { $newTranslationFiles[$fileName] = array(); } if (is_array($translation2)) { $parsedTranslations = array(); $this->parseTranslations(null, $translation2, $parsedTranslations); foreach ($parsedTranslations as $parsedKey => $parsedTranslation) { if (array_key_exists($parsedKey, $newTranslationFiles[$fileName]) == false) { $newTranslationFiles[$fileName][$parsedKey] = array(); if ($domain != 'messages') { $newTranslationFiles[$fileName][$parsedKey]['domain'] = $domain; } $newTranslationFiles[$fileName][$parsedKey]['value'] = array(); } $newTranslationFiles[$fileName][$parsedKey]['value'][$lang] = $parsedTranslation; // multiline if (strpos($parsedTranslation, "\n")) { $newTranslationFiles[$fileName][$parsedKey]['multiline'] = true; } // plural if (strpos($parsedTranslation, "|")) { $newTranslationFiles[$fileName][$parsedKey]['plural'] = true; } } } } } } } if ($progress instanceof ProgressBar) { $progress->advance(); } } // écriture des fichiers foreach ($newTranslationFiles as $newTranslationFile => $newTranslations) { $fileName = 'app' . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translatable_label' . DIRECTORY_SEPARATOR . $newTranslationFile; file_put_contents($fileName, Yaml::dump($newTranslations, 3)); } }
/** * CommandValidator constructor. * * @param Kernel $kernel */ public function __construct(Kernel $kernel) { $this->_kernel = $kernel; $this->_app = new Application($kernel); foreach ($kernel->getBundles() as $bundle) { if ($bundle instanceof Bundle) { $bundle->registerCommands($this->_app); } } }
/** * @param Kernel $kernel * @return array */ protected function getUserBundles(Kernel $kernel) { $bundles = []; /** @var Bundle $bundle */ foreach ($kernel->getBundles() as $bundle) { if (strpos($bundle->getPath(), 'vendor') === false) { $bundles[] = $bundle; } } return $bundles; }
protected function execute(InputInterface $input, OutputInterface $output) { $dumper = new Dumper(); $bundles = $this->kernel->getBundles(); $configs = $this->generator->generate(); /** @var Bundle $bundle */ foreach ($bundles as $bundle) { foreach ($configs as $entity => $config) { if (strpos($entity, $bundle->getNamespace()) === false) { continue; } $refl = new \ReflectionClass($entity); $factoryDir = $this->getDirectory($bundle); $file = $factoryDir . $refl->getShortName() . '.yml'; if (!file_exists($factoryDir)) { mkdir($factoryDir, 0777, true); } $content = $dumper->dump([$entity => $config], 4); // TODO check for existing files and merge them file_put_contents($file, $content); } } }
/** * Returns a list of namespaces as array with a forward slash to split the namespace & bundle. * * @param Kernel $kernel * @return array */ private function getNamespaceAutoComplete(Kernel $kernel) { $ret = array(); foreach ($kernel->getBundles() as $k => $v) { $ret[] = $this->fixNamespace($v->getNamespace()); } return $ret; }