[FrameworkBundle] removed init:bundle (replaced by the generator bundle in Symfony SE)
This commit is contained in:
parent
e717c99f3b
commit
7117f41b38
@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Bundle\FrameworkBundle\Generator\Generator;
|
||||
|
||||
/**
|
||||
* Initializes a new bundle.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class InitBundleCommand extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
* @see Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDefinition(array(
|
||||
new InputArgument('namespace', InputArgument::REQUIRED, 'The namespace of the bundle to create'),
|
||||
new InputArgument('dir', InputArgument::REQUIRED, 'The directory where to create the bundle'),
|
||||
new InputArgument('bundleName', InputArgument::OPTIONAL, 'The optional bundle name'),
|
||||
new InputOption('format', '', InputOption::VALUE_REQUIRED, 'Use the format for configuration files (php, xml, or yml)', 'yml')
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
The <info>init:bundle</info> command generates a new bundle with a basic skeleton.
|
||||
|
||||
<info>./app/console init:bundle "Vendor\HelloBundle" src [bundleName]</info>
|
||||
|
||||
The bundle namespace must end with "Bundle" (e.g. <comment>Vendor\HelloBundle</comment>)
|
||||
and can be placed in any directory (e.g. <comment>src</comment>).
|
||||
|
||||
If you don't specify a bundle name (e.g. <comment>HelloBundle</comment>), the bundle name will
|
||||
be the concatenation of the namespace segments (e.g. <comment>VendorHelloBundle</comment>).
|
||||
EOT
|
||||
)
|
||||
->setName('init:bundle')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command
|
||||
*
|
||||
* @throws \InvalidArgumentException When namespace doesn't end with Bundle
|
||||
* @throws \RuntimeException When bundle can't be executed
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!preg_match('/Bundle$/', $namespace = $input->getArgument('namespace'))) {
|
||||
throw new \InvalidArgumentException('The namespace must end with Bundle.');
|
||||
}
|
||||
|
||||
// validate namespace
|
||||
$namespace = strtr($namespace, '/', '\\');
|
||||
if (preg_match('/[^A-Za-z0-9_\\\-]/', $namespace)) {
|
||||
throw new \InvalidArgumentException('The namespace contains invalid characters.');
|
||||
}
|
||||
|
||||
// user specified bundle name?
|
||||
$bundle = $input->getArgument('bundleName');
|
||||
if (!$bundle) {
|
||||
$bundle = strtr($namespace, array('\\' => ''));
|
||||
}
|
||||
|
||||
if (!preg_match('/Bundle$/', $bundle)) {
|
||||
throw new \InvalidArgumentException('The bundle name must end with Bundle.');
|
||||
}
|
||||
|
||||
// validate that the namespace is at least one level deep
|
||||
if (false === strpos($namespace, '\\')) {
|
||||
$msg = array();
|
||||
$msg[] = sprintf('The namespace must contain a vendor namespace (e.g. "VendorName\%s" instead of simply "%s").', $namespace, $namespace);
|
||||
$msg[] = 'If you\'ve specified a vendor namespace, did you forget to surround it with quotes (init:bundle "Acme\BlogBundle")?';
|
||||
|
||||
throw new \InvalidArgumentException(implode("\n\n", $msg));
|
||||
}
|
||||
|
||||
$dir = $input->getArgument('dir');
|
||||
|
||||
// add trailing / if necessary
|
||||
$dir = '/' === substr($dir, -1, 1) ? $dir : $dir.'/';
|
||||
|
||||
$targetDir = $dir.strtr($namespace, '\\', '/');
|
||||
|
||||
if (file_exists($targetDir)) {
|
||||
throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle));
|
||||
}
|
||||
|
||||
$filesystem = $this->getContainer()->get('filesystem');
|
||||
$filesystem->mirror(__DIR__.'/../Resources/skeleton/bundle/generic', $targetDir);
|
||||
$filesystem->mirror(__DIR__.'/../Resources/skeleton/bundle/'.$input->getOption('format'), $targetDir);
|
||||
|
||||
Generator::renderDir($targetDir, array(
|
||||
'namespace' => $namespace,
|
||||
'bundle' => $bundle,
|
||||
));
|
||||
|
||||
rename($targetDir.'/Bundle.php', $targetDir.'/'.$bundle.'.php');
|
||||
|
||||
$output->writeln('<comment>Summary of actions</comment>');
|
||||
$output->writeln(sprintf('- The bundle "<info>%s</info>" was created at "<info>%s</info>" and is using the namespace "<info>%s</info>".', $bundle, $targetDir, $namespace));
|
||||
$output->writeln(sprintf('- The bundle contains a sample controller, a sample template and a sample routing file.'));
|
||||
|
||||
$output->writeln('');
|
||||
$output->writeln('<comment>Follow-up actions</comment>');
|
||||
|
||||
$output->writeln('- Enable the bundle inside the AppKernel::registerBundles() method.');
|
||||
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/page_creation.html#create-the-bundle</info>');
|
||||
|
||||
$output->writeln('- Ensure that the namespace is registered with the autoloader.');
|
||||
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/page_creation.html#autoloading-introduction-sidebar</info>');
|
||||
|
||||
$output->writeln('- If using routing, import the bundle\'s routing resource.');
|
||||
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/routing.html#including-external-routing-resources</info>');
|
||||
|
||||
$output->writeln('- Starting building your bundle!');
|
||||
$output->writeln(' Resource: <info>http://symfony.com/doc/2.0/book/page_creation.html#the-hello-symfony-page</info>');
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Generator;
|
||||
|
||||
/**
|
||||
* Generator is the base class for all generators.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Generator
|
||||
{
|
||||
/**
|
||||
* Renders a single line. Looks for {{ var }}
|
||||
*
|
||||
* @param string $string
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function renderString($string, array $parameters)
|
||||
{
|
||||
$replacer = function ($match) use ($parameters)
|
||||
{
|
||||
return isset($parameters[$match[1]]) ? $parameters[$match[1]] : $match[0];
|
||||
};
|
||||
|
||||
return preg_replace_callback('/{{\s*(.+?)\s*}}/', $replacer, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a file by replacing the contents of $file with rendered output.
|
||||
*
|
||||
* @param string $file filename for the file to be rendered
|
||||
* @param array $parameters
|
||||
*/
|
||||
static public function renderFile($file, array $parameters)
|
||||
{
|
||||
file_put_contents($file, static::renderString(file_get_contents($file), $parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a directory recursively
|
||||
*
|
||||
* @param string $dir Path to the directory that will be recursively rendered
|
||||
* @param array $parameters
|
||||
*/
|
||||
static public function renderDir($dir, array $parameters)
|
||||
{
|
||||
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
|
||||
if ($file->isFile()) {
|
||||
static::renderFile((string) $file, $parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace {{ namespace }};
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class {{ bundle }} extends Bundle
|
||||
{
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace {{ namespace }}\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
return $this->render('{{ bundle }}:Default:index.html.twig');
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
Hello!
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
$collection = new RouteCollection();
|
||||
/*
|
||||
$collection->add('homepage', new Route('/', array(
|
||||
'_controller' => '{{ bundle }}:Default:index',
|
||||
)));
|
||||
*/
|
||||
return $collection;
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<routes xmlns="http://symfony.com/schema/routing"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<!--
|
||||
<route id="homepage" pattern="/">
|
||||
<default key="_controller">{{ bundle }}:Default:denied</default>
|
||||
</route>
|
||||
//-->
|
||||
</routes>
|
@ -1,3 +0,0 @@
|
||||
#homepage:
|
||||
# pattern: /
|
||||
# defaults: { _controller: {{ bundle }}:Default:index }
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Generator;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Generator\Generator;
|
||||
use Symfony\Component\HttpKernel\Util\Filesystem;
|
||||
|
||||
class GeneratorTest extends TestCase
|
||||
{
|
||||
protected $dir;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$dir = __DIR__.'/fixtures/';
|
||||
|
||||
$this->dir = sys_get_temp_dir().'/symfony2gen';
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->mirror($dir, $this->dir);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->remove($this->dir);
|
||||
|
||||
$this->dir = null;
|
||||
}
|
||||
|
||||
public function testRenderString()
|
||||
{
|
||||
$template = 'Hi {{ you }}, my name is {{ me }}!';
|
||||
$expected = 'Hi {{ you }}, my name is Kris!';
|
||||
|
||||
$this->assertEquals(Generator::renderString($template, array('me' => 'Kris')), $expected, '::renderString() does not modify unknown parameters');
|
||||
}
|
||||
|
||||
public function testRenderFile()
|
||||
{
|
||||
Generator::renderFile($this->dir.'/template.txt', array('me' => 'Fabien'));
|
||||
|
||||
$this->assertEquals('Hello Fabien', file_get_contents($this->dir.'/template.txt'), '::renderFile() renders a file');
|
||||
}
|
||||
|
||||
public function testRenderDir()
|
||||
{
|
||||
Generator::renderDir($this->dir, array('me' => 'Fabien'));
|
||||
|
||||
$this->assertEquals('Hello Fabien', file_get_contents($this->dir.'/template.txt'), '::renderDir() renders a directory');
|
||||
$this->assertEquals('Hello Fabien', file_get_contents($this->dir.'/foo/bar.txt'), '::renderDir() renders a directory');
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
Hello {{ me }}
|
@ -1 +0,0 @@
|
||||
Hello {{ me }}
|
@ -1 +0,0 @@
|
||||
Hello {{ me }}
|
Reference in New Issue
Block a user