Skip to content

Commit

Permalink
Merge pull request #2218 from acrobat/sf4-prepare-generators
Browse files Browse the repository at this point in the history
[GeneratorBundle] Prepare generators for sf4 support
  • Loading branch information
Kristof Jochmans committed Jan 14, 2019
2 parents b71e049 + 5b13cdf commit 9e6fed2
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 2 deletions.
Expand Up @@ -5,6 +5,7 @@
use Kunstmaan\AdminBundle\Form\WysiwygType;
use Kunstmaan\GeneratorBundle\Helper\CommandAssistant;
use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils;
use Kunstmaan\GeneratorBundle\Helper\Sf4AppBundle;
use Kunstmaan\MediaBundle\Form\Type\MediaType;
use Kunstmaan\NodeBundle\Form\Type\URLChooserType;
use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCommand;
Expand All @@ -20,6 +21,7 @@
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -230,6 +232,10 @@ private function fixNamespace($namespace)
*/
protected function askForBundleName($objectName, $namespace = null, $questionMoreBundles = "\nIn which bundle do you want to create the %s", $questionOneBundle = "The %s will be created for the <comment>%s</comment> bundle.\n")
{
if (Kernel::VERSION_ID >= 40000) {
return new Sf4AppBundle($this->getContainer()->getParameter('kernel.project_dir'));
}

$ownBundles = $this->getOwnBundles();
if (count($ownBundles) <= 0) {
$this->assistant->writeError("Looks like you don't have created any bundles for your project...", true);
Expand Down
Expand Up @@ -39,8 +39,7 @@ public function setContainer(ContainerInterface $container = null)
*/
public function load(ObjectManager $manager)
{
$tokenGenerator = $this->container->get('fos_user.util.token_generator');
$password = substr($tokenGenerator->generateToken(), 0, 8);
$password = substr(rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '='), 0, 8);

$user1 = $this->createUser(
$manager,
Expand Down
33 changes: 33 additions & 0 deletions src/Kunstmaan/GeneratorBundle/Generator/KunstmaanGenerator.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* Class that contains all common generator logic.
Expand Down Expand Up @@ -471,4 +472,36 @@ protected function getRepositoryGenerator()
{
return new EntityRepositoryGenerator();
}

/**
* @internal
*/
protected function getTemplateDir(BundleInterface $bundle)
{
if ($this->isSymfony4()) {
return $this->container->getParameter('kernel.project_dir') . '/templates';
}

return $bundle->getPath() . '/Resources/views';
}

/**
* @internal
*/
protected function getAssetsDir(BundleInterface $bundle)
{
if ($this->isSymfony4()) {
return $this->container->getParameter('kernel.project_dir') . '/assets';
}

return $bundle->getPath() . '/Resources';
}

/**
* @internal
*/
protected function isSymfony4()
{
return Kernel::VERSION_ID >= 40000;
}
}
113 changes: 113 additions & 0 deletions src/Kunstmaan/GeneratorBundle/Helper/Sf4AppBundle.php
@@ -0,0 +1,113 @@
<?php

namespace Kunstmaan\GeneratorBundle\Helper;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

/**
* @internal
*/
final class Sf4AppBundle implements BundleInterface
{
private $projectDir;

public function __construct($projectDir)
{
$this->projectDir = $projectDir;
}

/**
* Boots the Bundle.
*/
public function boot()
{
//no-op
}

/**
* Shutdowns the Bundle.
*/
public function shutdown()
{
//no-op
}

/**
* Builds the bundle.
*
* It is only ever called once when the cache is empty.
*/
public function build(ContainerBuilder $container)
{
//no-op
}

/**
* Returns the container extension that should be implicitly loaded.
*
* @return ExtensionInterface|null The default extension or null if there is none
*/
public function getContainerExtension()
{
//no-op
}

/**
* Returns the bundle name (the class short name).
*
* @return string The Bundle name
*/
public function getName()
{
return 'App';
}

/**
* Gets the Bundle namespace.
*
* @return string The Bundle namespace
*/
public function getNamespace()
{
return 'App';
}

/**
* Gets the Bundle directory path.
*
* The path should always be returned as a Unix path (with /).
*
* @return string The Bundle absolute path
*/
public function getPath()
{
return $this->projectDir . '/src';
}

/**
* Sets the container.
*/
public function setContainer(ContainerInterface $container = null)
{
//no-op
}

/**
* Returns the bundle name that this bundle overrides.
*
* Despite its name, this method does not imply any parent/child relationship
* between the bundles, just a way to extend and override an existing
* bundle.
*
* @return string The Bundle name it overrides or null if no parent
*
* @deprecated This method is deprecated as of 3.4 and will be removed in 4.0.
*/
public function getParent()
{
//no-op
}
}
1 change: 1 addition & 0 deletions src/Kunstmaan/MediaBundle/Resources/config/handlers.yml
Expand Up @@ -47,3 +47,4 @@ services:
- [ setSlugifier, ['@kunstmaan_utilities.slugifier']]
tags:
- { name: 'kunstmaan_media.media_handler' }
public: true
1 change: 1 addition & 0 deletions src/Kunstmaan/MediaBundle/Resources/config/services.yml
Expand Up @@ -57,6 +57,7 @@ services:
kunstmaan_media.media_creator_service:
class: '%kunstmaan_media.media_creator_service.class%'
arguments: ['@service_container']
public: true

kunstmaan_media.repository.folder:
class: Kunstmaan\MediaBundle\Repository\FolderRepository
Expand Down
1 change: 1 addition & 0 deletions src/Kunstmaan/NodeBundle/Resources/config/services.yml
Expand Up @@ -131,6 +131,7 @@ services:
- [ setEntityManager, [ '@doctrine.orm.entity_manager' ] ]
- [ setACLPermissionCreatorService, [ '@kunstmaan_node.acl_permission_creator_service' ] ]
- [ setUserEntityClass, [ '%fos_user.model.user.class%' ] ]
public: true

kunstmaan_node.acl_permission_creator_service:
class: Kunstmaan\NodeBundle\Helper\Services\ACLPermissionCreatorService
Expand Down
1 change: 1 addition & 0 deletions src/Kunstmaan/PagePartBundle/Resources/config/services.yml
Expand Up @@ -73,6 +73,7 @@ services:
class: 'Kunstmaan\PagePartBundle\Helper\Services\PagePartCreatorService'
calls:
- [ setEntityManager, [ '@doctrine.orm.entity_manager' ] ]
public: true

kunstmaan_pageparts.edit_node.listener:
class: 'Kunstmaan\PagePartBundle\EventListener\NodeListener'
Expand Down
Expand Up @@ -13,6 +13,7 @@ services:

kunstmaan_utilities.slugifier:
class: '%kunstmaan_utilities.slugifier.class%'
public: true

kunstmaan_utilities.twig.extension:
class: Kunstmaan\UtilitiesBundle\Twig\UtilitiesTwigExtension
Expand Down

0 comments on commit 9e6fed2

Please sign in to comment.