getPath() public method

Gets the Bundle directory path.
public getPath ( ) : string
return string The Bundle absolute path
 /**
  * @param Bundle          $bundle
  * @param OutputInterface $output
  * @param array           $parameters
  */
 public function generateBehatTests(Bundle $bundle, OutputInterface $output, array $parameters)
 {
     $dirPath = sprintf("%s/Features", $bundle->getPath());
     $skeletonDir = sprintf("%s/Features", $this->fullSkeletonDir);
     // First copy all the content
     $this->filesystem->mirror($this->fullSkeletonDir, $bundle->getPath());
     // Now render the Context files to replace the namespace etc.
     if ($handle = opendir($skeletonDir . "/Context")) {
         while (false !== ($entry = readdir($handle))) {
             // Check to make sure we skip hidden folders
             // And we render the files ending in .php
             if (substr($entry, 0, 1) != '.' && substr($entry, -strlen(".php")) === ".php") {
                 $this->renderFile("/Features/Context/" . $entry, $dirPath . "/Context/" . $entry, $parameters);
             }
         }
         closedir($handle);
     }
     $featureContext = $dirPath . "/Context/FeatureContext.php";
     if ($this->filesystem->exists($featureContext)) {
         $contents = file_get_contents($featureContext);
         $contents = str_replace('-adminpwd-', $this->container->getParameter('kunstmaan_admin.admin_password'), $contents);
         file_put_contents($featureContext, $contents);
     }
     $output->writeln('Generating Behat Tests : <info>OK</info>');
 }
 /**
  * @param Bundle      $bundle
  * @param string[]    $filters
  * @param string      $connection
  * @param string|null $locale
  */
 public function loadFixtures(Bundle $bundle, array $filters, $connection, $locale = null)
 {
     if (false === is_dir(sprintf('%s/Resources/fixtures/orm', $bundle->getPath()))) {
         return;
     }
     $files = (new Finder())->files()->in(sprintf('%s/Resources/fixtures/orm', $bundle->getPath()))->sortByName();
     foreach ($filters as $filter) {
         $files->name($filter);
     }
     foreach ($files as $file) {
         $event = new Event($bundle, $file);
         $this->dispatcher->dispatch(Events::PRE_LOAD, $event);
         $event->setObjects($this->getFixtures($connection, $locale)->loadFiles($file));
         $this->dispatcher->dispatch(Events::POST_LOAD, $event);
     }
 }
 /**
  * Generate a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance
  *
  * @param ClassMetadataInfo     $metadata
  * @param Bundle                $bundle
  * @param string                $entity
  * @param array                 $fields
  * @param bool                  $hasI18n
  * @param bool                  $isTimestampable
  * @param bool                  $isSluggable
  *
  * @return string $code
  */
 public function generateEntityClass(ClassMetadataInfo $metadata, $bundle = null, $entity = null, $fields = array(), $hasI18n = false, $isTimestampable = false, $isSluggable = false)
 {
     $target = sprintf('%s/Entity/%s.php', $bundle->getPath(), $entity);
     $namespace = $this->generateEntityNamespace($metadata);
     $code = str_replace('<spaces>', $this->spaces, $this->generateEntityBody($metadata));
     $bundleName = explode('\\Entity', $metadata->name);
     $routePrefix = strtolower(str_replace('\\', '_', str_replace('Bundle', '', $bundleName[0]))) . '_backend';
     $routeName = $routePrefix . strtolower(str_replace('\\', '_', $bundleName[1]));
     // Track all the translation fields and check if it contains the fieldName 'name'
     // and check if the name field is i18n
     $containNameField = false;
     $nameIsI18n = false;
     foreach ($fields as $field) {
         if ($field['fieldName'] == 'name') {
             $containNameField = true;
             if (substr(strtolower($field['i18n']), 0, 1) == 'y') {
                 $nameIsI18n = true;
             }
         }
     }
     if ($containNameField) {
         $functionName = '$this->getName()';
     } else {
         $functionName = '$this->getEntityName()';
     }
     $this->renderFile('entity/Entity.php.twig', $target, array('namespace' => $namespace, 'route' => $routeName, 'entity' => $entity, 'entity_var' => $this->getEntityVar($entity), 'code' => $code, 'name_function' => $functionName, 'is_timestampable' => $isTimestampable, 'is_sluggable' => $isSluggable, 'sluggable_name' => !$nameIsI18n && $isSluggable, 'has_i18n' => $hasI18n));
 }
Beispiel #4
0
 public static function addBundle(Bundle $bundle)
 {
     $extension = $bundle->getContainerExtension();
     if ($extension) {
         self::$extensions[] = $extension;
     }
     self::$bundlePaths[] = $bundle->getPath();
 }
 /**
  * Return the package prefix for a given bundle.
  *
  * @param Bundle $bundle
  * @param string $baseDirectory The base directory to exclude from prefix.
  *
  * @return string
  */
 protected function getPackagePrefix(Bundle $bundle, $baseDirectory = '')
 {
     $parts = explode(DIRECTORY_SEPARATOR, realpath($bundle->getPath()));
     $length = count(explode('\\', $bundle->getNamespace())) * -1;
     $prefix = implode(DIRECTORY_SEPARATOR, array_slice($parts, 0, $length));
     $prefix = ltrim(str_replace($baseDirectory, '', $prefix), DIRECTORY_SEPARATOR);
     if (!empty($prefix)) {
         $prefix = str_replace(DIRECTORY_SEPARATOR, '.', $prefix) . '.';
     }
     return $prefix;
 }
 /**
  * Load the generators confirming to default naming rules in the given bundle.
  * @param Bundle $bundle
  */
 private function loadGeneratorsForBundle(Bundle $bundle)
 {
     $dir = "{$bundle->getPath()}/Generator";
     if (is_dir($dir)) {
         $finder = new Finder();
         $finder->files()->name('*Generator.php')->in($dir);
         $prefix = $bundle->getNamespace() . '\\Generator';
         /** @var SplFileInfo $file */
         foreach ($finder as $file) {
             $this->loadGeneratorInBundle($file, $prefix);
         }
     }
 }
Beispiel #7
0
 /**
  * Deletes bundle migration classes for a given driver which are above a
  * reference version.
  *
  * @param \Symfony\Component\HttpKernel\Bundle\Bundle   $bundle
  * @param string                                        $driverName
  * @param string                                        $referenceVersion
  * @return array The migration files that were deleted
  */
 public function deleteUpperMigrationClasses(Bundle $bundle, $driverName, $referenceVersion)
 {
     $migrations = new \DirectoryIterator("{$bundle->getPath()}/Migrations/{$driverName}");
     $deletedVersions = array();
     foreach ($migrations as $migration) {
         if (preg_match('#Version(\\d+)\\.php#', $migration->getFilename(), $matches)) {
             if ($matches[1] > $referenceVersion) {
                 $this->fileSystem->remove(array($migration->getPathname()));
                 $deletedVersions[] = $migration->getFilename();
             }
         }
     }
     return $deletedVersions;
 }
 /**
  * Generate a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance
  *
  * @param ClassMetadataInfo     $metadata
  * @param Bundle                $bundle
  * @param string                $entity
  * @param array                 $fields
  * @param bool                  $isSluggable
  *
  * @return string $code
  */
 public function generateEntityClass(ClassMetadataInfo $metadata, $bundle = null, $entity = null, $fields = array(), $isSluggable = false)
 {
     $target = sprintf('%s/Entity/%s.php', $bundle->getPath(), $entity);
     $namespace = $this->generateEntityNamespace($metadata);
     $code = str_replace('<spaces>', $this->spaces, $this->generateEntityBody($metadata));
     $bundleName = explode('\\Entity', $metadata->name);
     $routePrefix = strtolower(str_replace('\\', '_', str_replace('Bundle', '', $bundleName[0]))) . '_backend';
     $routeName = $routePrefix . strtolower(str_replace('\\', '_', $bundleName[1]));
     // Track all the translation fields and check if it contains the fieldName 'name'
     // or a slug
     $containNameField = false;
     foreach ($fields as $field) {
         if ($field['fieldName'] == 'name' && substr(strtolower($field['i18n']), 0, 1) == 'y') {
             $containNameField = true;
         }
     }
     $this->renderFile('entity/EntityTranslation.php.twig', $target, array('namespace' => $namespace, 'route' => $routeName, 'entity' => $entity, 'code' => $code, 'is_sluggable' => $isSluggable, 'sluggable_name' => $isSluggable && $containNameField));
 }
 /**
  * Transform classname to a path $foundBundle substract it to get the destination
  *
  * @param Bundle $bundle
  * @return string
  */
 protected function findBasePathForBundle($bundle)
 {
     $path = str_replace('\\', '/', $bundle->getNamespace());
     $search = str_replace('\\', '/', $bundle->getPath());
     $destination = str_replace('/' . $path, '', $search, $c);
     if ($c != 1) {
         throw new \RuntimeException(sprintf('Can\'t find base path for bundle (path: "%s", destination: "%s").', $path, $destination));
     }
     return $destination;
 }
 /**
  * @param DialogHelper    $dialog      The dialog helper
  * @param InputInterface  $input       The command input
  * @param OutputInterface $output      The command output
  * @param Bundle          $bundle      The bundle
  * @param string          $entityClass The classname of the entity
  *
  * @return void
  */
 protected function updateRouting(DialogHelper $dialog, InputInterface $input, OutputInterface $output, Bundle $bundle, $entityClass)
 {
     $auto = true;
     $multilang = false;
     if ($input->isInteractive()) {
         $multilang = $dialog->askConfirmation($output, $dialog->getQuestion('Is it a multilanguage site', 'yes', '?'), true);
         $auto = $dialog->askConfirmation($output, $dialog->getQuestion('Do you want to update the routing automatically', 'yes', '?'), true);
     }
     $prefix = $multilang ? '/{_locale}' : '';
     $code = sprintf("%s:\n", strtolower($bundle->getName()) . '_' . strtolower($entityClass) . '_admin_list');
     $code .= sprintf("    resource: @%s/Controller/%sAdminListController.php\n", $bundle->getName(), $entityClass);
     $code .= "    type:     annotation\n";
     $code .= sprintf("    prefix:   %s/admin/%s/\n", $prefix, strtolower($entityClass));
     if ($multilang) {
         $code .= "    requirements:\n";
         $code .= "         _locale: %requiredlocales%\n";
     }
     if ($auto) {
         $file = $bundle->getPath() . '/Resources/config/routing.yml';
         $content = '';
         if (file_exists($file)) {
             $content = file_get_contents($file);
         } elseif (!is_dir($dir = dirname($file))) {
             mkdir($dir, 0777, true);
         }
         $content .= "\n";
         $content .= $code;
         if (false === file_put_contents($file, $content)) {
             $output->writeln($dialog->getHelperSet()->get('formatter')->formatBlock("Failed adding the content automatically", 'error'));
         } else {
             return;
         }
     }
     $output->writeln('Add the following to your routing.yml');
     $output->writeln('/*******************************/');
     $output->write($code);
     $output->writeln('/*******************************/');
 }
Beispiel #11
0
 /**
  * @param Bundle $bundle
  * @param string $namespace
  *
  * @return string
  */
 protected function getPackageFromBundle(Bundle $bundle, $namespace)
 {
     //find relative path from namespace to bundle->getNamespace()
     $baseNamespace = (new \ReflectionClass($bundle))->getNamespaceName();
     if (0 === strpos($namespace, $baseNamespace)) {
         //base namespace fits
         //eg.
         //  Base: Jarves/JarvesBundle => Jarves
         //  Model namespace: Jarves\Model
         //  strpos(Jarves\Model, Jarves) === 0
         // $namespaceDiff = Model
         $namespaceDiff = substr($namespace, strlen($baseNamespace) + 1);
         $bundlePath = realpath($bundle->getPath()) . '/' . str_replace('\\', '/', $namespaceDiff);
         $appPath = realpath($this->getApplication()->getKernel()->getRootDir() . '/..');
         $path = static::getRelativePath($bundlePath, $appPath);
         return str_replace('/', '.', $path);
     }
     //does not match or its a absolute path, so return it without suffix
     if ('\\' === $namespace[0]) {
         $namespace = substr($namespace, 1);
     }
     return str_replace('\\', '.', $namespace);
 }
Beispiel #12
0
 /**
  * Process plugin
  *
  * @param Bundle $plugin Plugin
  *
  * @return array Plugin configuration
  */
 protected function processPlugin(Bundle $plugin)
 {
     $resourcePath = $plugin->getPath() . '/Resources/config/external.yml';
     return file_exists($resourcePath) ? Yaml::parse(file_get_contents($resourcePath)) : [];
 }
Beispiel #13
0
 public function getPath()
 {
     return parent::getPath() . '/bundle';
 }
Beispiel #14
0
 private function getConfiguration(Bundle $bundle)
 {
     if (isset($this->cacheConfigs[$bundle->getName()])) {
         return $this->cacheConfigs[$bundle->getName()];
     }
     $driverName = $this->connection->getDriver()->getName();
     $migrationsDir = "{$bundle->getPath()}/Migrations/{$driverName}";
     $migrationsName = "{$bundle->getName()} migration";
     $migrationsNamespace = "{$bundle->getNamespace()}\\Migrations\\{$driverName}";
     $migrationsTableName = 'doctrine_' . strtolower($bundle->getName()) . '_versions';
     $config = new Configuration($this->connection);
     $config->setName($migrationsName);
     $config->setMigrationsDirectory($migrationsDir);
     $config->setMigrationsNamespace($migrationsNamespace);
     $config->setMigrationsTableName($migrationsTableName);
     if (is_dir($migrationsDir)) {
         $config->registerMigrationsFromDirectory($migrationsDir);
     }
     $this->cacheConfigs[$bundle->getName()] = $config;
     return $config;
 }
Beispiel #15
0
 /**
  * @param Bundle $bundle bundle
  *
  * @return array
  */
 public function getDefaultDirectoriesForBundle(Bundle $bundle)
 {
     return array(sprintf('%s/Tests/Units', $bundle->getPath()), sprintf('%s/Tests/Controller', $bundle->getPath()));
 }
 /**
  * @param Bundle          $bundle     The bundle
  * @param string          $entity     The name of the entity
  * @param array           $parameters The template parameters
  * @param OutputInterface $output
  *
  * @throws \RuntimeException
  */
 public function generateFixtures(Bundle $bundle, $entity, array $parameters, OutputInterface $output)
 {
     $dirPath = $bundle->getPath() . '/DataFixtures/ORM/ArticleGenerator';
     $skeletonDir = $this->skeletonDir . '/DataFixtures/ORM/ArticleGenerator';
     try {
         $this->generateSkeletonBasedClass($skeletonDir, $entity, $dirPath, 'ArticleFixtures', $parameters);
     } catch (\Exception $error) {
         throw new \RuntimeException($error->getMessage());
     }
     $output->writeln('Generating fixtures : <info>OK</info>');
 }
 protected function getConfigFilePath($filename)
 {
     $format = "%s/Resources/config/%s.yml";
     return sprintf($format, $this->currentBundle->getPath(), $filename);
 }
 /**
  * {@inheritdoc}
  */
 public function getPath()
 {
     return dirname(parent::getPath());
 }
 /**
  * @param Bundle        $bundle     The bundle
  * @param string        $entityName The entity name
  * @param ClassMetadata $metadata   The meta data
  *
  * @throws \RuntimeException
  */
 public function generateAdminType(Bundle $bundle, $entityName, ClassMetadata $metadata)
 {
     $className = sprintf("%sAdminType", $entityName);
     $dirPath = sprintf("%s/Form", $bundle->getPath());
     $classPath = sprintf("%s/%s.php", $dirPath, str_replace('\\', '/', $className));
     if (file_exists($classPath)) {
         throw new \RuntimeException(sprintf('Unable to generate the %s class as it already exists under the %s file', $className, $classPath));
     }
     $this->setSkeletonDirs(array($this->skeletonDir));
     $this->renderFile('/Form/EntityAdminType.php', $classPath, array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle, 'entity_class' => $entityName, 'fields' => $this->getFieldsFromMetadata($metadata)));
 }
 /**
  * Transform classname to a path $foundBundle substract it to get the destination
  *
  * @param Bundle $bundle
  * @return string
  */
 protected function findBasePathForBundle($bundle)
 {
     $path = str_replace('\\', '/', $bundle->getNamespace());
     $destination = str_replace('/' . $path, "", $bundle->getPath(), $c);
     if ($c != 1) {
         throw new \RuntimeException("Something went terribly wrong.");
     }
     return $destination;
 }
 /**
  * @param $bundle
  * @return string
  */
 protected function getDirectory(Bundle $bundle)
 {
     $path = $bundle->getPath();
     return $path . '/Resources/config/factrine/';
 }
Beispiel #22
0
 /**
  * Return services.yml file path
  *
  * @param BaseBundle $bundle
  * @return string
  */
 protected function getYamlFilePath(BaseBundle $bundle)
 {
     return $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'services.yml';
 }