Skip to content
This repository has been archived by the owner on Sep 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #11 from KnpLabs/app-and-resources
Browse files Browse the repository at this point in the history
Returning `app` and `Resources` folders
  • Loading branch information
everzet committed Mar 2, 2012
2 parents e45cd73 + a0c3535 commit 201cea9
Show file tree
Hide file tree
Showing 51 changed files with 73 additions and 379 deletions.
47 changes: 3 additions & 44 deletions Command/AssetsInstallCommand.php
Expand Up @@ -32,6 +32,9 @@ class AssetsInstallCommand extends BaseCommand
protected function configure()
{
$this
->setDefinition(array(
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory (usually "web")', 'web'),
))
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
->setDescription('Installs bundles web assets under a public web directory')
Expand All @@ -58,48 +61,4 @@ protected function configure()
->setName('assets:install')
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$targetArg = rtrim($this->getContainer()->getParameter('kernel.web_dir'), '/');

if (!is_dir($targetArg)) {
throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
}

if (!function_exists('symlink') && $input->getOption('symlink')) {
throw new \InvalidArgumentException('The symlink() function is not available on your system. You need to install the assets without the --symlink option.');
}

$filesystem = $this->getContainer()->get('filesystem');

// Create the bundles directory otherwise symlink will fail.
$filesystem->mkdir($targetArg.'/bundles/', 0777);

foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
$originDir = $bundle->getPath().'/Resources/public';
if ($bundle instanceof AppBundle) {
$originDir = $bundle->getPath().'/public';
}

if (is_dir($originDir)) {
$targetDir = $targetArg.'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName()));

$output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $bundle->getNamespace(), $targetDir));

$filesystem->remove($targetDir);

if ($input->getOption('symlink')) {
$filesystem->symlink($originDir, $targetDir);
} else {
$filesystem->mkdir($targetDir, 0777);
// We use a custom iterator to ignore VCS files
$filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir));
}
}
}
}
}
4 changes: 2 additions & 2 deletions Command/GenerateControllerCommand.php
Expand Up @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeLn(' method <info>already exists</info>');
}

$viewPath = sprintf('%s/views/%s/%s.html.twig',
$viewPath = sprintf('%s/Resources/views/%s/%s.html.twig',
$bundle->getPath(), str_replace('\\', '/', $controller), $action
);

Expand All @@ -113,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeLn(' view <info>already exists</info>');
}

$routingPath = sprintf('%s/config/routing.yml', $bundle->getPath());
$routingPath = sprintf('%s/Resources/config/routing.yml', $bundle->getPath());
$routeName = $this->underscore($name).'_'.$this->underscore($action);
$routePath = '/'.$this->underscore($name).'/'.$this->underscore($action);
$controller = 'App:'.str_replace('/', '\\', $controller).':'.$action;
Expand Down
2 changes: 1 addition & 1 deletion Command/GenerateTwigExtensionCommand.php
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

// generate the service definition
$servicesPath = sprintf('%s/config/services.yml', $bundle->getPath());
$servicesPath = sprintf('%s/Resources/config/services.yml', $bundle->getPath());

$output->writeLn(sprintf("\n".'- <comment>app.twig.%s_extension</comment> service:',
strtolower($name)
Expand Down
48 changes: 0 additions & 48 deletions DependencyInjection/Compiler/ApplicationStructurePass.php

This file was deleted.

Expand Up @@ -20,39 +20,27 @@
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class AsseticTemplateResourcesPass extends BasePass
class ApplicationTemplateResourcesPass extends BasePass
{
/**
* Patches kernel parameters.
*
* @param ContainerBuilder $container Container instance
*/
public function process(ContainerBuilder $container)
{
if (!$container->getParameter('knp_rad.application_structure')) {
return;
}

parent::process($container);
}

/**
* {@inheritdoc}
*/
protected function setBundleDirectoryResources(ContainerBuilder $container, $engine, $bundleDirName, $bundleName)
{
if ('App' === $bundleName) {
parent::setBundleDirectoryResources(
$container,
$engine,
$container->getParameter('kernel.project_dir'),
$bundleName
);
}
}

/**
* {@inheritdoc}
*/
protected function setAppDirectoryResources(ContainerBuilder $container, $engine)
{
$container->setDefinition(
'assetic.'.$engine.'_directory_resource.kernel',
new DirectoryResourceDefinition('', $engine, array(
$container->getParameter('kernel.project_dir').'/views'
))
);
}
}
62 changes: 0 additions & 62 deletions DependencyInjection/Compiler/TranslationsLocatorPass.php

This file was deleted.

3 changes: 0 additions & 3 deletions DependencyInjection/Configuration.php
Expand Up @@ -52,9 +52,6 @@ public function getConfigTreeBuilder()
->booleanNode('application_views')
->defaultFalse()
->end()
->booleanNode('application_structure')
->defaultFalse()
->end()
->end()
;

Expand Down
21 changes: 3 additions & 18 deletions DependencyInjection/Extension/AppExtension.php
Expand Up @@ -12,7 +12,6 @@
namespace Knp\Bundle\RadBundle\DependencyInjection\Extension;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Definition\Processor;
Expand Down Expand Up @@ -45,14 +44,10 @@ public function __construct($path)
*/
public function load(array $configs, ContainerBuilder $container)
{
$xmlLoader = $this->getXmlFileLoader($container);
$ymlLoader = $this->getYamlFileLoader($container);

if (file_exists($services = $this->path.'/config/services.xml')) {
$xmlLoader->load($services);
}
if (file_exists($services = $this->path.'/config/services.yml')) {
$ymlLoader->load($services);
if (file_exists($this->path.'/Resources/config/services.yml')) {
$ymlLoader->load('services.yml');
}

foreach ($configs as $config) {
Expand All @@ -72,23 +67,13 @@ public function getAlias()
return 'app';
}

/**
* Returns new container XmlFileLoader.
*
* @return XmlFileLoader
*/
protected function getXmlFileLoader(ContainerBuilder $container)
{
return new XmlFileLoader($container, new FileLocator($this->path.'/config'));
}

/**
* Returns new container YamlFileLoader.
*
* @return YamlFileLoader
*/
protected function getYamlFileLoader(ContainerBuilder $container)
{
return new YamlFileLoader($container, new FileLocator($this->path.'/config'));
return new YamlFileLoader($container, new FileLocator($this->path.'/Resources/config'));
}
}
10 changes: 5 additions & 5 deletions DependencyInjection/Extension/ConfigurationDumper.php
Expand Up @@ -31,14 +31,14 @@ public function getAlias()

public function isAlreadyDumped()
{
return file_exists($this->configPath.'/bundles/'.$this->getAlias().'.yml');
return file_exists($this->configPath.'/config/'.$this->getAlias().'.yml');
}

public function dump()
{
$output = sprintf('<comment>%s:</comment>', $this->getAlias())."\n";

if (!file_exists($dir = $this->configPath.'/bundles')) {
if (!file_exists($dir = $this->configPath.'/config')) {
mkdir($dir, 0777, true);
}
if (!file_exists($dir = $this->configPath.'/routing')) {
Expand All @@ -56,9 +56,9 @@ public function dump()

public function dumpProvidedConfig()
{
$configPath = $this->configPath.'/bundles/'.$this->getAlias().'.yml';
$configPath = $this->configPath.'/config/'.$this->getAlias().'.yml';
file_put_contents($configPath, "\n".file_get_contents(
$this->templatesPath.'/bundles/config.yml'
$this->templatesPath.'/config.yml'
), FILE_APPEND);

$output = sprintf(' <info>+config</info> %s',
Expand Down Expand Up @@ -87,7 +87,7 @@ public function dumpProvidedConfig()

public function dumpEmptyConfig()
{
$path = $this->configPath.'/bundles/'.$this->getAlias().'.yml';
$path = $this->configPath.'/config/'.$this->getAlias().'.yml';

file_put_contents($path, <<<YAML
all: ~
Expand Down
2 changes: 0 additions & 2 deletions DependencyInjection/KnpRadExtension.php
Expand Up @@ -73,7 +73,5 @@ public function load(array $configs, ContainerBuilder $container)
}

$loader->load('assetic_coffee_fix.xml');

$container->setParameter('knp_rad.application_structure', $config['application_structure']);
}
}
2 changes: 1 addition & 1 deletion HttpKernel/KernelConfiguration.php
Expand Up @@ -104,7 +104,7 @@ public function getProjectName()
{
if (null === $this->projectName) {
throw new \InvalidArgumentException(
'Specify your `project` name inside config/project.yml or config/project.local.yml'
'Specify your `project` name inside app/kernel.yml or app/kernel.custom.yml'
);
}

Expand Down

0 comments on commit 201cea9

Please sign in to comment.