コード例 #1
0
 public function generateRestRouting(BundleInterface $bundle, $controller)
 {
     $file = $bundle->getPath() . '/Resources/config/routing.rest.yml';
     if (file_exists($file)) {
         $content = file_get_contents($file);
     } elseif (!is_dir($dir = $bundle->getPath() . '/Resources/config')) {
         mkdir($dir);
     }
     $resource = $bundle->getNamespace() . "\\Controller\\" . $controller . 'Controller';
     $name = strtolower(preg_replace('/([A-Z])/', '_\\1', $bundle->getName() . $controller . '_rest'));
     $name_prefix = strtolower(preg_replace('/([A-Z])/', '_\\1', $bundle->getName() . '_api_'));
     if (!isset($content)) {
         $content = '';
     } else {
         $yml = new Yaml();
         $route = $yml->parse($content);
         if (isset($route[$name])) {
             return false;
         }
     }
     $content .= sprintf("\n%s:\n    type: rest\n    resource: %s\n    name_prefix: %s\n", $name, $resource, $name_prefix);
     $flink = fopen($file, 'w');
     if ($flink) {
         $write = fwrite($flink, $content);
         if ($write) {
             fclose($flink);
         } else {
             throw new \RunTimeException(sprintf('We cannot write into file "%s", has that file the correct access level?', $file));
         }
     } else {
         throw new \RunTimeException(sprintf('Problems with generating file "%s", did you gave write access to that directory?', $file));
     }
 }
コード例 #2
0
 /**
  * Generates the datatable class if it does not exist.
  *
  * @param BundleInterface $bundle     The bundle in which to create the class
  * @param string          $entity     The entity relative class name
  * @param array           $fields     The datatable fields
  * @param boolean         $clientSide The client side flag
  * @param string          $ajaxUrl    The ajax url
  * @param boolean         $bootstrap3 The bootstrap3 flag
  * @param boolean         $admin      The admin flag
  *
  * @throws RuntimeException
  */
 public function generate(BundleInterface $bundle, $entity, array $fields, $clientSide, $ajaxUrl, $bootstrap3, $admin)
 {
     $parts = explode("\\", $entity);
     $entityClass = array_pop($parts);
     $this->className = $entityClass . 'Datatable';
     $dirPath = $bundle->getPath() . '/Datatables';
     if (true === $admin) {
         $this->className = $entityClass . 'AdminDatatable';
         $dirPath = $bundle->getPath() . '/Datatables/Admin';
     }
     $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Datatable.php';
     if (true === $admin) {
         $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'AdminDatatable.php';
     }
     if (file_exists($this->classPath)) {
         throw new RuntimeException(sprintf('Unable to generate the %s datatable class as it already exists under the %s file', $this->className, $this->classPath));
     }
     $parts = explode('\\', $entity);
     array_pop($parts);
     // set ajaxUrl
     if (false === $clientSide) {
         // server-side
         if (!$ajaxUrl) {
             $this->ajaxUrl = strtolower($entityClass) . '_results';
         } else {
             $this->ajaxUrl = $ajaxUrl;
         }
     }
     $routePref = strtolower($entityClass);
     if (true === $admin) {
         $routePref = DatatablesRoutingLoader::PREF . strtolower($entityClass);
         $bootstrap3 = true;
     }
     $this->renderFile('class.php.twig', $this->classPath, array('namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'entity_class' => $entityClass, 'bundle' => $bundle->getName(), 'datatable_class' => $this->className, 'datatable_name' => $admin ? strtolower($entityClass) . '_admin_datatable' : strtolower($entityClass) . '_datatable', 'fields' => $fields, 'client_side' => (bool) $clientSide, 'ajax_url' => $admin ? DatatablesRoutingLoader::PREF . $this->ajaxUrl : $this->ajaxUrl, 'bootstrap3' => (bool) $bootstrap3, 'admin' => (bool) $admin, 'route_pref' => $routePref));
 }
コード例 #3
0
 /**
  * @param BundleInterface $bundle         The bundle
  * @param string          $entity         The entity name
  * @param string          $format         The format
  * @param array           $fields         The fields
  * @param boolean         $withRepository With repository
  * @param string          $prefix         A prefix
  *
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $entity, $format, array $fields, $withRepository, $prefix)
 {
     // configure the bundle (needed if the bundle does not contain any Entities yet)
     $config = $this->registry->getManager(null)->getConfiguration();
     $config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity'), $config->getEntityNamespaces()));
     $entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
     $entityPath = $bundle->getPath() . '/Entity/' . str_replace('\\', '/', $entity) . '.php';
     if (file_exists($entityPath)) {
         throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
     }
     $class = new ClassMetadataInfo($entityClass);
     if ($withRepository) {
         $entityClass = preg_replace('/\\\\Entity\\\\/', '\\Repository\\', $entityClass, 1);
         $class->customRepositoryClassName = $entityClass . 'Repository';
     }
     foreach ($fields as $field) {
         $class->mapField($field);
     }
     $class->setPrimaryTable(array('name' => $prefix . $this->getTableNameFromEntityName($entity)));
     $entityGenerator = $this->getEntityGenerator();
     $entityCode = $entityGenerator->generateEntityClass($class);
     $mappingPath = $mappingCode = false;
     $this->filesystem->mkdir(dirname($entityPath));
     file_put_contents($entityPath, $entityCode);
     if ($mappingPath) {
         $this->filesystem->mkdir(dirname($mappingPath));
         file_put_contents($mappingPath, $mappingCode);
     }
     if ($withRepository) {
         $path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
         $this->getRepositoryGenerator()->writeEntityRepositoryClass($class->customRepositoryClassName, $path);
     }
     $this->addGeneratedEntityClassLoader($entityClass, $entityPath);
 }
コード例 #4
0
 /**
  * @param  \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
  * @param  string                                               $document
  * @param  array                                                $fields
  * @param  Boolean                                              $withRepository
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $document, array $fields, $withRepository)
 {
     $config = $this->documentManager->getConfiguration();
     $config->addDocumentNamespace($bundle->getName(), $bundle->getNamespace() . '\\Document');
     $documentClass = $config->getDocumentNamespace($bundle->getName()) . '\\' . $document;
     $documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
     if (file_exists($documentPath)) {
         throw new \RuntimeException(sprintf('Document "%s" already exists.', $documentClass));
     }
     $class = new ClassMetadataInfo($documentClass);
     if ($withRepository) {
         $class->setCustomRepositoryClass($documentClass . 'Repository');
     }
     $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     foreach ($fields as $field) {
         $class->mapField($field);
     }
     $documentGenerator = $this->getDocumentGenerator();
     $documentCode = $documentGenerator->generateDocumentClass($class);
     $this->filesystem->mkdir(dirname($documentPath));
     file_put_contents($documentPath, rtrim($documentCode) . PHP_EOL, LOCK_EX);
     if ($withRepository) {
         $path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
         $this->getRepositoryGenerator()->writeDocumentRepositoryClass($class->customRepositoryClassName, $path);
     }
 }
コード例 #5
0
 /**
  * @param $dirs
  * @param array $classes
  * @param array $excludeClasses
  * @param string $pattern
  * @return array
  */
 protected function getClasses($dirs, $classes = array(), $excludeClasses = array(), $pattern = '*.php')
 {
     $basePath = $this->bundle->getPath();
     $dirs = array_map(function ($dir) use($basePath) {
         return $basePath . '/' . $dir;
     }, $dirs);
     $allClasses = $this->classFinder->findClasses($dirs, $basePath, $this->bundle->getNamespace(), $pattern);
     $allClasses = array_unique(array_merge($classes, $allClasses));
     return array_filter($allClasses, function ($class) use($excludeClasses) {
         return !in_array($class, $excludeClasses);
     });
 }
コード例 #6
0
 /**
  * Find templates in the given bundle.
  *
  * @param BundleInterface $bundle The bundle where to look for templates
  *
  * @return array of yaml paths
  */
 private function findGeneratorYamlInBundle(BundleInterface $bundle)
 {
     $yamls = array();
     if (!file_exists($bundle->getPath() . '/Resources/config')) {
         return $yamls;
     }
     $finder = new Finder();
     $finder->files()->name('generator.yml')->name('*-generator.yml')->in($bundle->getPath() . '/Resources/config');
     foreach ($finder as $file) {
         $yamls[$file->getRealPath()] = $file->getRealPath();
     }
     return $yamls;
 }
コード例 #7
0
 public function generate(BundleInterface $bundle, $controller, $routeFormat, $templateFormat, array $actions = array())
 {
     $dir = $bundle->getPath();
     $controllerFile = $dir . '/Controller/' . $controller . 'Controller.php';
     if (file_exists($controllerFile)) {
         throw new \RuntimeException(sprintf('Controller "%s" already exists', $controller));
     }
     // seeRoute
     $bundleShortName = substr($bundle->getName(), strlen('Webobs'), strlen($bundle->getName()) - (strlen('Bundle') + strlen('Webobs')));
     $seeRoute = 'webobs_' . strtolower($bundleShortName) . '_' . strtolower($controller) . '_see';
     $parameters = array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle->getName(), 'format' => array('routing' => $routeFormat, 'templating' => $templateFormat), 'entity' => $controller, 'seeRoute' => $seeRoute);
     foreach ($actions as $i => $action) {
         // get the actioname without the sufix Action (for the template logical name)
         $actions[$i]['basename'] = $action['name'];
         $params = $parameters;
         $params['action'] = $actions[$i];
         // create a template
         $template = $actions[$i]['template'];
         if ('default' == $template) {
             $template = $bundle->getName() . ':' . $controller . ':' . $action['name'] . '.html.' . $templateFormat;
         }
         $this->generateRouting($bundle, $controller, $actions[$i], $routeFormat);
     }
     $parameters['actions'] = $actions;
     $this->renderFile('controller/Controller.php.twig', $controllerFile, $parameters);
     $this->renderFile('controller/ControllerTest.php.twig', $dir . '/Tests/Controller/' . $controller . 'ControllerTest.php', $parameters);
 }
コード例 #8
0
ファイル: ModuleGenerator.php プロジェクト: clastic/clastic
 /**
  * <parameters>
  *  <parameter key="app.project.module.class">AppBundle\Module\ProjectModule</parameter>
  * </parameters>
  * <service id="app.project.module" class="%app.project.module.class%">
  *  <tag name="clastic.module" node_module="true" alias="project" />
  *  <tag name="clastic.node_form" build_service="app.project.module.form_build" />
  * </service>.
  *
  * @param BundleInterface $bundle
  * @param array           $data
  */
 private function updateDependencyInjectionXml(BundleInterface $bundle, array $data)
 {
     $file = $bundle->getPath() . '/Resources/config/services.xml';
     $xml = simplexml_load_file($file);
     $parameters = $xml->parameters ? $xml->parameters : $xml->addChild('parameters');
     $services = $xml->services ? $xml->services : $xml->addChild('services');
     $moduleServiceName = sprintf('%s.%s.module', $data['bundle_alias'], $data['identifier']);
     $moduleParameter = $parameters->addChild('parameter', sprintf('%s\\Module\\%sModule', $data['namespace'], $data['module']));
     $moduleParameter->addAttribute('key', sprintf('%s.class', $moduleServiceName));
     $formExtensionParameter = $parameters->addChild('parameter', sprintf('%s\\Form\\Module\\%sFormExtension', $data['namespace'], $data['module']));
     $formExtensionParameter->addAttribute('key', sprintf('%s.form_extension.class', $moduleServiceName));
     $moduleService = $services->addChild('service');
     $moduleService->addAttribute('id', sprintf('%s.%s.module', $data['bundle_alias'], $data['identifier']));
     $moduleService->addAttribute('class', sprintf('%%%s.class%%', $moduleServiceName));
     $moduleTag = $moduleService->addChild('tag');
     $moduleTag->addAttribute('name', 'clastic.module');
     $moduleTag->addAttribute('node_module', 'true');
     $moduleTag->addAttribute('alias', $data['identifier']);
     $formExtensionTag = $moduleService->addChild('tag');
     $formExtensionTag->addAttribute('name', 'clastic.node_form');
     $formExtensionTag->addAttribute('build_service', sprintf('%s.form_extension', $moduleServiceName));
     $formExtensionService = $services->addChild('service');
     $formExtensionService->addAttribute('id', sprintf('%s.form_extension', $moduleServiceName));
     $formExtensionService->addAttribute('class', sprintf('%%%s.form_extension.class%%', $moduleServiceName));
     $xml->saveXML($file);
 }
 /**
  * Generate Fixture from bundle name, entity name, fixture name and ids
  *
  * @param BundleInterface $bundle
  * @param string          $entity
  * @param string          $name
  * @param array           $ids
  * @param string|null     $connectionName
  */
 public function generate(BundleInterface $bundle, $entity, $name, array $ids, $order, $connectionName = null)
 {
     // configure the bundle (needed if the bundle does not contain any Entities yet)
     $config = $this->registry->getManager($connectionName)->getConfiguration();
     $config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity'), $config->getEntityNamespaces()));
     $fixtureFileName = $this->getFixtureFileName($entity, $name, $ids);
     $entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
     $fixturePath = $bundle->getPath() . '/DataFixtures/ORM/' . $fixtureFileName . '.php';
     $bundleNameSpace = $bundle->getNamespace();
     if (file_exists($fixturePath)) {
         throw new \RuntimeException(sprintf('Fixture "%s" already exists.', $fixtureFileName));
     }
     $class = new ClassMetadataInfo($entityClass);
     $fixtureGenerator = $this->getFixtureGenerator();
     $fixtureGenerator->setFixtureName($fixtureFileName);
     $fixtureGenerator->setBundleNameSpace($bundleNameSpace);
     $fixtureGenerator->setMetadata($class);
     $fixtureGenerator->setFixtureOrder($order);
     /** @var EntityManager $em */
     $em = $this->registry->getManager($connectionName);
     $repo = $em->getRepository($class->rootEntityName);
     if (empty($ids)) {
         $items = $repo->findAll();
     } else {
         $items = $repo->findById($ids);
     }
     $fixtureGenerator->setItems($items);
     $fixtureCode = $fixtureGenerator->generateFixtureClass($class);
     $this->filesystem->mkdir(dirname($fixturePath));
     file_put_contents($fixturePath, $fixtureCode);
 }
コード例 #10
0
 /**
  * Gets the prefix of the asset with the given bundle
  *
  * @param BundleInterface $bundle Bundle to fetch in
  *
  * @throws \InvalidArgumentException
  * @return string Prefix
  */
 public function getPrefix(BundleInterface $bundle)
 {
     if (!is_dir($bundle->getPath() . '/Resources/public')) {
         throw new \InvalidArgumentException(sprintf('Bundle %s does not have Resources/public folder', $bundle->getName()));
     }
     return sprintf('/bundles/%s', preg_replace('/bundle$/', '', strtolower($bundle->getName())));
 }
コード例 #11
0
    /**
     * Generates the entity form class if it does not exist.
     *
     * @param BundleInterface $bundle The bundle in which to create the class
     * @param string $entity The entity relative class name
     * @param ClassMetadataInfo $metadata The entity metadata class
     */
    public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
    {
        $parts       = explode('\\', $entity);
        $entityClass = array_pop($parts);

        $this->className = $entityClass.'Type';
        $dirPath         = $bundle->getPath().'/Form';
        $this->classPath = $dirPath.'/'.str_replace('\\', '/', $entity).'Type.php';

        if (file_exists($this->classPath)) {
            throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
        }

        if (count($metadata->identifier) > 1) {
            throw new \RuntimeException('The form generator does not support entity classes with multiple primary keys.');
        }

        $parts = explode('\\', $entity);
        array_pop($parts);

        $this->renderFile($this->skeletonDir, 'FormType.php', $this->classPath, array(
            'dir'              => $this->skeletonDir,
            'fields'           => $this->getFieldsFromMetadata($metadata),
            'namespace'        => $bundle->getNamespace(),
            'entity_namespace' => implode('\\', $parts),
            'form_class'       => $this->className,
        ));
    }
コード例 #12
0
 /**
  * Generates the entity form class if it does not exist.
  *
  * @param BundleInterface $bundle The bundle in which to create the class
  * @param string $entity The entity relative class name
  * @param ClassMetadataInfo $metadata The entity metadata class
  */
 public function generate(BundleInterface $bundle, $entity, $fields, $options = null, $search = false)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $this->className = $entityClass . 'Type';
     $dirPath = $bundle->getPath() . '/Form';
     if ($search) {
         $className = $entityClass . 'SearchType';
         $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'SearchType.php';
     } else {
         $className = $entityClass . 'Type';
         $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Type.php';
     }
     if (file_exists($this->classPath)) {
         unlink($this->classPath);
         //throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
     }
     $choice = false;
     foreach ($fields as $field) {
         if ($field['fragment'] == 'choice') {
             $choice = true;
         }
     }
     $parts = explode('\\', $entity);
     array_pop($parts);
     $this->renderFile($this->skeletonDir, 'FormType_tab.php', $this->classPath, array('dir' => $this->skeletonDir, 'fields' => $fields, 'namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'form_class' => $className, 'form_type_name' => strtolower(str_replace('\\', '_', $bundle->getNamespace()) . ($parts ? '_' : '') . implode('_', $parts) . '_' . $this->className), 'entityName' => $entityClass, 'choice' => $choice, 'options' => $options));
 }
コード例 #13
0
 /**
  * Export the translations from a given path
  *
  * @param BundleInterface $bundle
  * @param string          $locale
  * @param string          $outputDir
  * @param bool            $excel
  * @return array
  */
 private function exportTranslations(BundleInterface $bundle, $locale, $outputDir, $excel = false)
 {
     // if the bundle does not have a translation dir, continue to the next one
     $translationPath = sprintf('%s%s', $bundle->getPath(), '/Resources/translations');
     if (!is_dir($translationPath)) {
         return array();
     }
     // create a catalogue, and load the messages
     $catalogue = new MessageCatalogue($locale);
     /** @var \Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader $loader */
     $loader = $this->getContainer()->get('translation.loader');
     $loader->loadMessages($translationPath, $catalogue);
     // export in desired format
     if ($excel) {
         // check if the PHPExcel library is installed
         if (!class_exists('PHPExcel')) {
             throw new \RuntimeException('PHPExcel library is not installed. Please do so if you want to export translations as Excel file.');
         }
         $dumper = new ExcelFileDumper();
     } else {
         $dumper = new CsvFileDumper();
     }
     /** @var DumperInterface $dumper */
     return $dumper->dump($catalogue, array('path' => $outputDir, 'bundleName' => $bundle->getName()));
 }
コード例 #14
0
 /**
  * Generates the entity form class if it does not exist.
  *
  * @param BundleInterface   $bundle   The bundle in which to create the class
  * @param string            $entity   The entity relative class name
  * @param ClassMetadataInfo $metadata The entity metadata class
  */
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
 {
     if (is_null($this->src)) {
         $this->src = $bundle->getPath();
     }
     $this->entity = $entity;
     $dirPath = $this->src . '/Form/Type';
     $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'FormType.php';
     if (count($metadata->identifier) > 1) {
         throw new \RuntimeException('The form generator does not support entity classes with multiple primary keys.');
     }
     $fields = $this->getFieldsFromMetadata($metadata);
     $maxColumnNameSize = 0;
     foreach ($fields as $field) {
         $maxColumnNameSize = max($field['columnNameSize'] + 2, $maxColumnNameSize);
     }
     $options = array('fields' => $fields, 'form_class' => $entity . 'FormType', 'form_label' => $entity, 'max_column_name_size' => $maxColumnNameSize);
     $this->tplOptions = array_merge($this->tplOptions, $options);
     $this->generateForm();
     $this->generateServices();
     if ($this->getContainer()->getParameter('dev_generator_tool.generate_translation')) {
         $g = new TranslationGenerator($this->filesystem, sprintf('%s/Resources/translations', $this->src), $entity, $fields);
         $g->generate();
     }
 }
コード例 #15
0
 /**
  * Update the page section config files
  */
 private function generateSectionConfig()
 {
     if (count($this->sections) > 0) {
         $dir = $this->bundle->getPath() . '/Resources/config/pageparts/';
         foreach ($this->sections as $section) {
             $data = Yaml::parse($dir . $section);
             if (!array_key_exists('types', $data)) {
                 $data['types'] = array();
             }
             $class = $this->bundle->getNamespace() . '\\Entity\\PageParts\\' . $this->entity;
             $found = false;
             foreach ($data['types'] as $type) {
                 if ($type['class'] == $class) {
                     $found = true;
                 }
             }
             if (!$found) {
                 $data['types'][] = array('name' => str_replace('PagePart', '', $this->entity), 'class' => $class);
             }
             $ymlData = Yaml::dump($data, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false);
             file_put_contents($dir . $section, $ymlData);
         }
         $this->assistant->writeLine('Updating ' . $this->entity . ' section config: <info>OK</info>');
     }
 }
コード例 #16
0
 protected function getSkeletonDirs(BundleInterface $bundle = null)
 {
     $skeletonDirs = array();
     if (isset($bundle) && is_dir($dir = $bundle->getPath() . '/Resources/SensioGeneratorBundle/skeleton')) {
         $skeletonDirs[] = $dir;
     }
     if (is_dir($dir = $this->getContainer()->get('kernel')->getRootdir() . '/Resources/SensioGeneratorBundle/skeleton')) {
         $skeletonDirs[] = $dir;
     }
     $bundleDirs = $this->getContainer()->get('kernel')->locateResource('@SensioGeneratorBundle/Resources/skeleton', null, false);
     $sensioGeneratorSkeletonPath = dirname(__DIR__) . '/Resources/skeleton';
     /*
      * Assert: $bundleDirs is an array that contains $sensioGeneratorSkeletonPath and maybe some more
      * Since $skeletonDirs is a prioritized list we want to exclude $sensioGeneratorSkeletonPath from $bundleDirs
      * now and make sure it is added at the end of the list.
      */
     foreach ($bundleDirs as $dir) {
         if ($dir != $sensioGeneratorSkeletonPath) {
             $skeletonDirs[] = $dir;
         }
     }
     $skeletonDirs[] = $sensioGeneratorSkeletonPath;
     $skeletonDirs[] = __DIR__ . '/../Resources';
     return $skeletonDirs;
 }
コード例 #17
0
 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");
 }
コード例 #18
0
 /**
  * @param BundleInterface $bundle
  * @param string          $entity
  * @param string          $format
  * @param array           $fields
  *
  * @return EntityGeneratorResult
  *
  * @throws \Doctrine\ORM\Tools\Export\ExportException
  */
 public function generate(BundleInterface $bundle, $entity, $format, array $fields)
 {
     // configure the bundle (needed if the bundle does not contain any Entities yet)
     $config = $this->registry->getManager(null)->getConfiguration();
     $config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity'), $config->getEntityNamespaces()));
     $entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
     $entityPath = $bundle->getPath() . '/Entity/' . str_replace('\\', '/', $entity) . '.php';
     if (file_exists($entityPath)) {
         throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
     }
     $class = new ClassMetadataInfo($entityClass);
     $class->customRepositoryClassName = str_replace('\\Entity\\', '\\Repository\\', $entityClass) . 'Repository';
     $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     foreach ($fields as $field) {
         $class->mapField($field);
     }
     $entityGenerator = $this->getEntityGenerator();
     if ('annotation' === $format) {
         $entityGenerator->setGenerateAnnotations(true);
         $class->setPrimaryTable(array('name' => Inflector::tableize($entity)));
         $entityCode = $entityGenerator->generateEntityClass($class);
         $mappingPath = $mappingCode = false;
     } else {
         $cme = new ClassMetadataExporter();
         $exporter = $cme->getExporter('yml' == $format ? 'yaml' : $format);
         $mappingPath = $bundle->getPath() . '/Resources/config/doctrine/' . str_replace('\\', '.', $entity) . '.orm.' . $format;
         if (file_exists($mappingPath)) {
             throw new \RuntimeException(sprintf('Cannot generate entity when mapping "%s" already exists.', $mappingPath));
         }
         $mappingCode = $exporter->exportClassMetadata($class);
         $entityGenerator->setGenerateAnnotations(false);
         $entityCode = $entityGenerator->generateEntityClass($class);
     }
     $entityCode = str_replace(array("@var integer\n", "@var boolean\n", "@param integer\n", "@param boolean\n", "@return integer\n", "@return boolean\n"), array("@var int\n", "@var bool\n", "@param int\n", "@param bool\n", "@return int\n", "@return bool\n"), $entityCode);
     $this->filesystem->mkdir(dirname($entityPath));
     file_put_contents($entityPath, $entityCode);
     if ($mappingPath) {
         $this->filesystem->mkdir(dirname($mappingPath));
         file_put_contents($mappingPath, $mappingCode);
     }
     $path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
     $this->getRepositoryGenerator()->writeEntityRepositoryClass($class->customRepositoryClassName, $path);
     $repositoryPath = $path . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class->customRepositoryClassName) . '.php';
     return new EntityGeneratorResult($entityPath, $repositoryPath, $mappingPath);
 }
コード例 #19
0
 /**
  * Generate the fixtures class.
  *
  * @param BundleInterface   $bundle     A bundle object
  * @param BundleInterface   $destBundle The destination bundle object
  * @param string            $entity     The entity relative class name
  * @param ClassMetadataInfo $metadata   The entity class metadata
  * @parma integer           $num        The number of fixtures to generate
  *
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, BundleInterface $destBundle, $entity, ClassMetadataInfo $metadata, $num = 1)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $dir = $destBundle->getPath() . '/DataFixtures/ORM/';
     $this->filesystem->mkdir($dir);
     $this->renderFile('fixtures/DataFixtures.php.twig', $dir . $entityClass . 'Data.php', array('namespace' => $destBundle->getNamespace(), 'bundle' => $bundle->getName(), 'entity' => $entity, 'entity_class' => $entityClass, 'fields' => $this->getFieldsFromMetadata($metadata), 'num' => $num));
 }
コード例 #20
0
 public function findAdminControllerClasses(BundleInterface $bundle)
 {
     $directory = $bundle->getPath() . '/Controller/Admin';
     $namespace = $bundle->getNamespace() . '\\Controller\\Admin';
     $interface = AdminControllerInterface::class;
     $classes = $this->findClassesImplementingInterface($directory, $namespace, $interface);
     return $classes;
 }
コード例 #21
0
 private function createDirectory(BundleInterface $bundle, OutputInterface $output)
 {
     $fs = new Filesystem();
     if (!is_dir($dir = $bundle->getPath() . self::DEFAULT_FORM_TYPE_DIRECTORY)) {
         $fs->mkdir($dir);
         $this->writeNewDirectory($output, $dir);
     }
     return $dir;
 }
コード例 #22
0
 /**
  * Generates the functional test class only.
  *
  */
 protected function generateTestClass()
 {
     $parts = explode('\\', $this->entity);
     $entityClass = array_pop($parts);
     $entityNamespace = implode('\\', $parts);
     $dir = $this->bundle->getPath() . '/Tests/Controller';
     $target = $dir . '/' . str_replace('\\', '/', $entityNamespace) . '/' . $entityClass . 'RESTControllerTest.php';
     $this->renderFile('rest/tests/test.php.twig', $target, array('route_prefix' => $this->routePrefix, 'route_name_prefix' => $this->routeNamePrefix, 'entity' => $this->entity, 'bundle' => $this->bundle->getName(), 'entity_class' => $entityClass, 'namespace' => $this->bundle->getNamespace(), 'entity_namespace' => $entityNamespace, 'actions' => $this->actions, 'form_type_name' => strtolower(str_replace('\\', '_', $this->bundle->getNamespace()) . ($parts ? '_' : '') . implode('_', $parts) . '_' . $entityClass . 'Type')));
 }
コード例 #23
0
 /**
  * @param BundleInterface $bundle
  * @param SwaggerDocument $document
  * @param string          $relativeNamespace
  */
 public function generate(BundleInterface $bundle, SwaggerDocument $document, $relativeNamespace = 'Model\\Resources')
 {
     $dir = $bundle->getPath();
     $parameters = ['namespace' => $bundle->getNamespace(), 'bundle' => $bundle->getName(), 'resource_namespace' => $relativeNamespace];
     foreach ($document->getResourceSchemas() as $typeName => $spec) {
         $resourceFile = "{$dir}/" . str_replace('\\', '/', $relativeNamespace) . "/{$typeName}.php";
         $this->renderFile('resource.php.twig', $resourceFile, array_merge($parameters, $spec, ['resource' => $typeName, 'resource_class' => $typeName]));
     }
 }
コード例 #24
0
 /**
  * @param string          $file
  * @param BundleInterface $bundle
  *
  * @return string|null
  */
 private function getClassFromFileAndBundle($file, BundleInterface $bundle)
 {
     $root = $bundle->getPath();
     if (0 !== strpos($file, $root)) {
         return;
     }
     $file = substr($file, strlen($root), -4);
     return sprintf('%s%s', $bundle->getNamespace(), str_replace(DIRECTORY_SEPARATOR, '\\', $file));
 }
コード例 #25
0
 /**
  * Generates the functional test class only.
  *
  */
 private function generateTestClass()
 {
     $parts = explode('\\', $this->document);
     $class = array_pop($parts);
     $namespace = implode('\\', $parts);
     $dir = $this->bundle->getPath() . '/Tests/Controller';
     $target = $dir . '/' . str_replace('\\', '/', $namespace) . '/' . $class . 'ControllerTest.php';
     $this->renderFile('tests/test.php.twig', $target, array('route_prefix' => $this->routePrefix, 'route_name_prefix' => $this->routeNamePrefix, 'document' => $this->document, 'document_class' => $class, 'namespace' => $this->bundle->getNamespace(), 'controller_namespace' => $namespace, 'actions' => $this->actions, 'form_type_name' => strtolower(str_replace('\\', '_', $this->bundle->getNamespace()) . ($parts ? '_' : '') . implode('_', $parts) . '_' . $class . 'Type'), 'dir' => $this->skeletonDir));
 }
コード例 #26
0
 /**
  * Generates the entity form class if it does not exist.
  *
  * @param BundleInterface   $bundle   The bundle in which to create the class
  * @param string            $entity   The entity relative class name
  * @param ClassMetadataInfo $metadata The entity metadata class
  * @param ArrayCollection   $options
  */
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata, ArrayCollection $options = null)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $this->generatedName = $entityClass;
     $dirPath = $bundle->getPath() . '/Entity';
     $this->filePath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Interface.php';
     $this->renderFile('entity/interface.php.twig', $this->filePath, ['namespace' => $bundle->getNamespace()]);
 }
コード例 #27
0
ファイル: CrudGenerator.php プロジェクト: vardius/crud-bundle
 protected function createDirectory($default)
 {
     $fs = new Filesystem();
     if (!is_dir($dir = $this->bundle->getPath() . $default)) {
         $fs->mkdir($dir);
         $this->output->writeln('>>  <info>Dir+</info>     ' . $dir);
     }
     return $dir;
 }
コード例 #28
0
 /**
  * @param  BundleInterface   $bundle
  * @param  string            $adminClassBasename
  * @param  string            $modelClass
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $adminClassBasename, $modelClass)
 {
     $this->class = sprintf('%s\\Admin\\%s', $bundle->getNamespace(), $adminClassBasename);
     $this->file = sprintf('%s/Admin/%s.php', $bundle->getPath(), str_replace('\\', '/', $adminClassBasename));
     $parts = explode('\\', $this->class);
     if (file_exists($this->file)) {
         throw new \RuntimeException(sprintf('Unable to generate the admin class "%s". The file "%s" already exists.', $this->class, realpath($this->file)));
     }
     $this->renderFile('Admin.php.twig', $this->file, array('classBasename' => array_pop($parts), 'namespace' => implode('\\', $parts), 'fields' => $this->modelManager->getExportFields($modelClass)));
 }
コード例 #29
0
 private function mergeDefaultSettings(BundleInterface $bundle, array $settings)
 {
     if (empty($settings['contexts'])) {
         $settings['contexts'] = array($bundle->getNamespace() . $this->contextClassSuffix);
     }
     if (empty($settings['paths'])) {
         $settings['paths'] = array($bundle->getPath() . $this->pathSuffix);
     }
     return $settings;
 }
コード例 #30
0
 /**
  * @param BundleInterface $bundle
  * @param string          $controllerClassBasename
  *
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $controllerClassBasename)
 {
     $this->class = sprintf('%s\\Controller\\%s', $bundle->getNamespace(), $controllerClassBasename);
     $this->file = sprintf('%s/Controller/%s.php', $bundle->getPath(), str_replace('\\', '/', $controllerClassBasename));
     $parts = explode('\\', $this->class);
     if (file_exists($this->file)) {
         throw new \RuntimeException(sprintf('Unable to generate the admin controller class "%s". The file "%s" already exists.', $this->class, realpath($this->file)));
     }
     $this->renderFile('AdminController.php.twig', $this->file, array('classBasename' => array_pop($parts), 'namespace' => implode('\\', $parts)));
 }