Skip to content

Commit

Permalink
refacto + install templates to web/images
Browse files Browse the repository at this point in the history
  • Loading branch information
Acrack committed Mar 26, 2014
1 parent af3f9b7 commit 53e6d08
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bigfoot\Bundle\CoreBundle\Command;
namespace Bigfoot\Bundle\CoreBundle\Command\Bigfoot;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\ArrayInput;
Expand All @@ -10,10 +10,12 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;

use Bigfoot\Bundle\CoreBundle\Command\BaseCommand;

/**
* Runs bigfoot:theme:install and assets:install
*/
class BigfootAssetsInstallCommand extends ContainerAwareCommand
class AssetsInstallCommand extends BaseCommand
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -43,12 +45,13 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$target = $input->getArgument('target');
$symlink = $input->getOption('symlink');
$target = $input->getArgument('target');
$symlink = $input->getOption('symlink');
$relative = $input->getOption('relative');

$input = new ArrayInput(array(
'target' => $target,
'--symlink' => $symlink,
'target' => $target,
'--symlink' => $symlink,
'--relative' => $relative,
));

Expand All @@ -59,6 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
protected function runCommand($name, ArrayInput $input, OutputInterface $output)
{
$command = $this->getApplication()->find($name);

return $command->run($input, $output);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php

namespace Bigfoot\Bundle\CoreBundle\Command;
namespace Bigfoot\Bundle\CoreBundle\Command\Bigfoot;

use Bigfoot\Bundle\CoreBundle\Generator\BigfootCrudGenerator;
use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

use Bigfoot\Bundle\CoreBundle\Command\BaseCommand;

/**
* Heavily based on \Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand.
*
* Class GenerateBigfootCrudCommand
* @package Bigfoot\Bundle\CoreBundle\Command
*/
class GenerateBigfootCrudCommand extends GenerateDoctrineCrudCommand
class GenerateCrudCommand extends GenerateDoctrineCrudCommand
{

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Bigfoot\Bundle\CoreBundle\Command;
namespace Bigfoot\Bundle\CoreBundle\Command\Bigfoot;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -9,10 +9,12 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;

use Bigfoot\Bundle\CoreBundle\Command\BaseCommand;

/**
* Command that places the active bigfoot theme web assets into a given directory.
*/
class BigfootThemeInstallCommand extends ContainerAwareCommand
class ThemeInstallCommand extends BaseCommand
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -67,13 +69,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
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');
$filesystem = $this->getContainer()->get('filesystem');
$themeBundle = $this->getContainer()->get('kernel')->getBundle($this->getContainer()->getParameter('bigfoot.theme.bundle'));
$contentBundle = $this->getContainer()->get('kernel')->getBundle('BigfootContentBundle');
$images = $contentBundle->getPath().'/Resources/public/images';

$this->recurseCopy($images, $targetArg.'/images');

$bundle = $this->getContainer()->get('kernel')->getBundle($this->getContainer()->getParameter('bigfoot.theme.bundle'));
if (is_dir($originDir = $bundle->getPath().'/Resources/assets')) {
if (is_dir($originDir = $themeBundle->getPath().'/Resources/assets')) {
$targetDir = $targetArg.'/admin';

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

$filesystem->remove($targetDir);

Expand All @@ -83,12 +89,31 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$relativeOriginDir = $originDir;
}

$filesystem->symlink($relativeOriginDir, $targetDir);
} else {
$filesystem->mkdir($targetDir, 0777);

// We use a custom iterator to ignore VCS files
$filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir));
}
}
}

protected function recurseCopy($src, $dst) {
$dir = opendir($src);
@mkdir($dst);

while (false !== ($file = readdir($dir))) {
if (($file != '.') && ( $file != '..' )) {
if (is_dir($src.'/'.$file)) {
$this->recurseCopy($src.'/'.$file, $dst.'/'.$file);
} else {
copy($src.'/'.$file, $dst.'/'.$file);
}
}
}

closedir($dir);
}
}

0 comments on commit 53e6d08

Please sign in to comment.