Esempio n. 1
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));
 }
 /**
  * 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);
 }
Esempio n. 3
0
 /**
  * Gets the metadata of all classes of a bundle.
  *
  * @param BundleInterface $bundle A BundleInterface instance
  *
  * @return ClassMetadataCollection A ClassMetadataCollection instance
  */
 public function getBundleMetadata(BundleInterface $bundle)
 {
     $namespace = $bundle->getNamespace();
     if (!($metadata = $this->getMetadataForNamespace($namespace))) {
         throw new \RuntimeException(sprintf('Bundle "%s" does not contain any mapped entities.', $bundle->getName()));
     }
     $path = $this->getBasePathForClass($bundle->getName(), $bundle->getNamespace(), $bundle->getPath());
     $metadata->setPath($path);
     $metadata->setNamespace($bundle->getNamespace());
     return $metadata;
 }
 /**
  * @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);
     });
 }
 /**
  * Adds a Manager service within the managers config file.
  *
  * @param BundleInterface $bundle
  * @param string $entity
  *
  * @return Boolean true if it worked, false otherwise
  *
  * @throws \RuntimeException If bundle is already imported
  */
 public function addResource(BundleInterface $bundle, $entity)
 {
     $managerService = sprintf('%s.manager.%s', Container::underscore(substr($bundle->getName(), 0, -6)), strtolower($entity));
     $managerClass = sprintf('%s\\Manager\\%sManager', $bundle->getNamespace(), ucfirst($entity));
     $entityClass = sprintf('%s\\Entity\\%s', $bundle->getNamespace(), ucfirst($entity));
     $content = Yaml::parse(file_get_contents($this->file));
     $content['parameters'][$managerService . '.class'] = $managerClass;
     $content['services'][$managerService] = array('class' => "%{$managerService}.class%", 'tags' => array(array('name' => 'voryx.manager')), 'arguments' => array($entityClass));
     $yaml = Yaml::dump($content, 4);
     if (false === file_put_contents($this->file, $yaml)) {
         return false;
     }
     return true;
 }
 /**
  * Adds an Admin service within the admin config file.
  *
  * @param BundleInterface $bundle
  * @param string $entity
  * @param string $group
  * @param string $label
  * @param string $translationDomain
  *
  * @return Boolean true if it worked, false otherwise
  *
  * @throws \RuntimeException If bundle is already imported
  */
 public function addResource(BundleInterface $bundle, $entity, $group, $label, $translationDomain = 'Sonata')
 {
     $adminService = sprintf('%s.admin.%s', Container::underscore(substr($bundle->getName(), 0, -6)), strtolower($entity));
     $adminClass = sprintf('%s\\Admin\\%sAdmin', $bundle->getNamespace(), ucfirst($entity));
     $entityClass = sprintf('%s\\Entity\\%s', $bundle->getNamespace(), ucfirst($entity));
     $content = Yaml::parse(file_get_contents($this->file));
     $content['parameters'][$adminService . '.class'] = $adminClass;
     $content['services'][$adminService] = array('class' => "%{$adminService}.class%", 'tags' => array(array('name' => 'sonata.admin', 'manager_type' => 'orm', 'group' => $group, 'label' => $label)), 'arguments' => array(null, $entityClass, null), 'calls' => array(array('setTranslationDomain', array($translationDomain))));
     $yaml = Yaml::dump($content, 4);
     if (false === file_put_contents($this->file, $yaml)) {
         return false;
     }
     return true;
 }
Esempio n. 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);
 }
 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));
     }
 }
    /**
     * 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,
        ));
    }
 /**
  * {@inheritdoc}
  */
 public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask)
 {
     $this->output->writeln(sprintf('Installing assets for <comment>%s</comment>', $bundle->getNamespace(), $targetDir));
     $effectiveSymlinkMask = $this->assetsInstaller->installBundleAssets($bundle, $targetDir, $symlinkMask);
     $this->output->writeln($this->provideResultComment($symlinkMask, $effectiveSymlinkMask));
     return $effectiveSymlinkMask;
 }
 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));
     }
     $parameters = array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle->getName(), 'format' => array('routing' => $routeFormat, 'templating' => $templateFormat), 'controller' => $controller);
     foreach ($actions as $i => $action) {
         // get the action name without the suffix Action (for the template logical name)
         $actions[$i]['basename'] = substr($action['name'], 0, -6);
         $params = $parameters;
         $params['action'] = $actions[$i];
         // create a template
         $template = $actions[$i]['template'];
         if ('default' == $template) {
             @trigger_error('The use of the "default" keyword is deprecated. Use the real template name instead.', E_USER_DEPRECATED);
             $template = $bundle->getName() . ':' . $controller . ':' . strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr(substr($action['name'], 0, -6), '_', '.'))) . '.html.' . $templateFormat;
         }
         if ('twig' == $templateFormat) {
             $this->renderFile('controller/Template.html.twig.twig', $dir . '/Resources/views/' . $this->parseTemplatePath($template), $params);
         } else {
             $this->renderFile('controller/Template.html.php.twig', $dir . '/Resources/views/' . $this->parseTemplatePath($template), $params);
         }
         $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);
 }
 /**
  * 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>');
     }
 }
 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));
     }
     $parameters = array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle->getName(), 'format' => array('routing' => $routeFormat, 'templating' => $templateFormat), 'controller' => $controller);
     foreach ($actions as $i => $action) {
         // get the actioname without the sufix Action (for the template logical name)
         $actions[$i]['basename'] = substr($action['name'], 0, -6);
         $params = $parameters;
         $params['action'] = $actions[$i];
         // create a template
         $template = $actions[$i]['template'];
         if ('default' == $template) {
             $template = $bundle->getName() . ':' . $controller . ':' . substr($action['name'], 0, -6) . '.html.' . $templateFormat;
         }
         if ('twig' == $templateFormat) {
             $this->renderFile('controller/Template.html.twig.twig', $dir . '/Resources/views/' . $this->parseTemplatePath($template), $params);
         } else {
             $this->renderFile('controller/Template.html.php.twig', $dir . '/Resources/views/' . $this->parseTemplatePath($template), $params);
         }
         $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);
 }
 /**
  * Generate the entity PHP code.
  *
  * @param BundleInterface $bundle
  * @param string          $name
  * @param array           $fields
  * @param string          $namePrefix
  * @param string          $dbPrefix
  * @param string|null     $extendClass
  *
  * @return array
  * @throws \RuntimeException
  */
 protected function generateEntity(BundleInterface $bundle, $name, $fields, $namePrefix, $dbPrefix, $extendClass = null)
 {
     // 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\\' . $namePrefix), $config->getEntityNamespaces()));
     $entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $namePrefix . '\\' . $name;
     $entityPath = $bundle->getPath() . '/Entity/' . $namePrefix . '/' . str_replace('\\', '/', $name) . '.php';
     if (file_exists($entityPath)) {
         throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
     }
     $class = new ClassMetadataInfo($entityClass, new UnderscoreNamingStrategy());
     foreach ($fields as $fieldSet) {
         foreach ($fieldSet as $fieldArray) {
             foreach ($fieldArray as $field) {
                 if (array_key_exists('joinColumn', $field)) {
                     $class->mapManyToOne($field);
                 } elseif (array_key_exists('joinTable', $field)) {
                     $class->mapManyToMany($field);
                 } else {
                     $class->mapField($field);
                 }
             }
         }
     }
     $class->setPrimaryTable(array('name' => strtolower($dbPrefix . strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name))) . 's'));
     $entityCode = $this->getEntityGenerator($extendClass)->generateEntityClass($class);
     return array($entityCode, $entityPath);
 }
 /**
  * @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);
 }
Esempio n. 16
0
 protected function generateExceptionClass(BundleInterface $bundle, $target)
 {
     if (!is_dir(dirname($target))) {
         mkdir(dirname($target));
     }
     $this->renderFile('form/form_exception.php.twig', $target, ['namespace' => $bundle->getNamespace()]);
 }
Esempio n. 17
0
 /**
  * @param string $class
  * @param BundleInterface $bundle
  *
  * @return boolean
  */
 public function isClassInBundle($class, BundleInterface $bundle)
 {
     if (false === $class instanceof \ReflectionClass) {
         $class = $this->reflection->createFromClass($class);
     }
     return true === strpos($class->getNamespaceName(), $bundle->getNamespace());
 }
 public function generateServiceId(BundleInterface $bundle, $className)
 {
     $namespace = $bundle->getNamespace();
     $alias = $bundle->getAlias();
     $bundleClass = substr($className, strlen($namespace) + 1);
     return sprintf('%s.%s', $alias, $this->makeParentDirAsClassifier($bundleClass));
 }
Esempio n. 19
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);
     }
 }
 /**
  * Generates the entity form class.
  *
  * @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 bool              $forceOverwrite If true, remove any existing form class before generating it again
  */
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata, $forceOverwrite = false)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $this->className = $entityClass . 'Type';
     $dirPath = $bundle->getPath() . '/Form';
     $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Type.php';
     if (!$forceOverwrite && 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('form/FormType.php.twig', $this->classPath, array('fields' => $this->getFieldsFromMetadata($metadata), 'fields_mapping' => $metadata->fieldMappings, 'namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'entity_class' => $entityClass, 'bundle' => $bundle->getName(), 'form_class' => $this->className, 'form_type_name' => strtolower(str_replace('\\', '_', $bundle->getNamespace()) . ($parts ? '_' : '') . implode('_', $parts) . '_' . substr($this->className, 0, -4)), 'configure_options_available' => method_exists('Symfony\\Component\\Form\\AbstractType', 'configureOptions')));
 }
 /**
  * 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));
 }
 /**
  * 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 generateFormFilter(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
 {
     $parts = explode('\\', $entity);
     $entityClass = array_pop($parts);
     $this->className = $entityClass . 'FilterType';
     $dirPath = $bundle->getPath() . '/Form';
     $this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'FilterType.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('form/FormFilterType.php.twig', $this->classPath, array('fields_data' => $this->getFieldsDataFromMetadata($metadata), 'namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'entity_class' => $entityClass, 'bundle' => $bundle->getName(), 'form_class' => $this->className, 'form_filter_type_name' => strtolower(str_replace('\\', '_', $bundle->getNamespace()) . ($parts ? '_' : '') . implode('_', $parts) . '_' . $this->className)));
 }
Esempio n. 23
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;
 }
 /**
  * @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));
 }
 /**
  * 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')));
 }
Esempio n. 26
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));
 }
Esempio n. 27
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]));
     }
 }
 /**
  * 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()]);
 }
 function let(KernelWrapper $kernel, BundleInterface $bundle1, BundleInterface $bundle2, ServiceNameGenerator $generator)
 {
     $kernel->getBundles()->willReturn([$bundle1, $bundle2]);
     $this->beConstructedWith($kernel, $generator);
     $bundle1->getNamespace()->willReturn('Company\\MyBundle');
     $bundle1->getName()->willReturn('bundle1');
     $bundle2->getNamespace()->willReturn('Company\\MyOther\\Bundle');
     $bundle2->getName()->willReturn('Bundle2');
 }
 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;
 }