Skip to content

Commit

Permalink
Merge branch 'feature/2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakaran committed Sep 17, 2017
2 parents 8d3ad63 + dbd894e commit a4e0391
Show file tree
Hide file tree
Showing 144 changed files with 2,572 additions and 7,116 deletions.
9 changes: 8 additions & 1 deletion AvanzuAdminThemeBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
namespace Avanzu\AdminThemeBundle;

use Avanzu\AdminThemeBundle\DependencyInjection\AssetsCompilerPass;
use Avanzu\AdminThemeBundle\DependencyInjection\Compiler\AsseticPass;
use Avanzu\AdminThemeBundle\DependencyInjection\Compiler\KnpMenuPass;
use Avanzu\AdminThemeBundle\DependencyInjection\Compiler\TwigPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class AvanzuAdminThemeBundle extends Bundle
{

public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new TwigPass());
}


}
252 changes: 252 additions & 0 deletions Command/InitializeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
<?php
/**
* InitializeCommand.php
* symfony3
* Date: 12.06.16
*/

namespace Avanzu\AdminThemeBundle\Command;



use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;

/**
* Class InitializeCommand
*
*/
class InitializeCommand extends ContainerAwareCommand
{

const METHOD_COPY = 'copy';
const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink';
const METHOD_RELATIVE_SYMLINK = 'relative symlink';

/**
* @var Filesystem
*/
private $filesystem;

/**
*
*/
protected function configure()
{
$this->setName('avanzu:admin:initialize')
->addOption('vendor-dir', null, InputOption::VALUE_OPTIONAL, 'path to vendors', 'vendor')
->addOption('theme-dir' , null, InputOption::VALUE_OPTIONAL, 'path to adminlte', 'almasaeed2010/adminlte')
->addOption('web-dir', null, InputOption::VALUE_OPTIONAL, 'path to web', 'web')
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
;
}

/**
* @param $appDir
* @param InputInterface $input
*
* @return string
*/
protected function getVendorDir(InputInterface $input)
{
return $input->getOption('vendor-dir');
}

/**
* @param $appDir
* @param InputInterface $input
*
* @return string
*/
protected function getThemeDir(InputInterface $input)
{
return sprintf('%s/%s', $this->getVendorDir( $input), $input->getOption('theme-dir'));
}

/**
* @param ContainerInterface $dic
* @param InputInterface $input
*
* @return object
*/
protected function getDirectorySetup(ContainerInterface $dic, InputInterface $input)
{
$appDir = $dic->getParameter('kernel.root_dir');
$projectDir = dirname($appDir);
$vendors = $this->getVendorDir($input);
$theme = $this->getThemeDir($input);
$self = dirname(__DIR__);

return (object)[
'app' => $appDir,
'project' => $projectDir,
'vendors' => $vendors,
'theme' => $theme,
'self' => $self,
'public' => $input->getOption('web-dir')
];

}

/**
* @param $originDir
* @param $targetDir
* @param $expectedMethod
*
* @return string
*/
protected function establishLink($originDir, $targetDir, $expectedMethod)
{
$this->filesystem->remove($targetDir);

if (self::METHOD_RELATIVE_SYMLINK === $expectedMethod) {
$method = $this->relativeSymlinkWithFallback($originDir, $targetDir);
} elseif (self::METHOD_ABSOLUTE_SYMLINK === $expectedMethod) {
$method = $this->absoluteSymlinkWithFallback($originDir, $targetDir);
} else {
$method = $this->hardCopy($originDir, $targetDir);
}

return $method;

}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$dic = $this->getContainer();
$fs = $dic->get('filesystem');
$folders = $this->getDirectorySetup($dic, $input);
$io = new SymfonyStyle($input, $output);
$this->filesystem = $fs;


if ($input->getOption('relative')) {
$expectedMethod = self::METHOD_RELATIVE_SYMLINK;
$io->text('Trying to install theme assets as <info>relative symbolic links</info>.');
} elseif ($input->getOption('symlink')) {
$expectedMethod = self::METHOD_ABSOLUTE_SYMLINK;
$io->text('Trying to install theme assets as <info>absolute symbolic links</info>.');
} else {
$expectedMethod = self::METHOD_COPY;
$io->text('Installing theme assets as <info>hard copies</info>.');
}


$fs->mkdir($folders->public . '/theme');

foreach ( ['bootstrap','dist','plugins','documentation', 'starter.html'] as $directory) {

$io->text("installing <info>$directory</info>");

$lnFrom = sprintf('%s/%s', $folders->theme, $directory);
$lnTo = sprintf('%s/theme/%s', $folders->public, $directory);

$this->establishLink( $lnFrom, $lnTo, $expectedMethod );
}
}


/**
* Try to create relative symlink.
*
* Falling back to absolute symlink and finally hard copy.
*
* @param string $originDir
* @param string $targetDir
*
* @return string
*/
private function relativeSymlinkWithFallback($originDir, $targetDir)
{
try {
$this->symlink($originDir, $targetDir, true);
$method = self::METHOD_RELATIVE_SYMLINK;
} catch (IOException $e) {
$method = $this->absoluteSymlinkWithFallback($originDir, $targetDir);
}

return $method;
}

/**
* Try to create absolute symlink.
*
* Falling back to hard copy.
*
* @param string $originDir
* @param string $targetDir
*
* @return string
*/
private function absoluteSymlinkWithFallback($originDir, $targetDir)
{
try {
$this->symlink($originDir, $targetDir);
$method = self::METHOD_ABSOLUTE_SYMLINK;
} catch (IOException $e) {
// fall back to copy
$method = $this->hardCopy($originDir, $targetDir);
}

return $method;
}

/**
* Creates symbolic link.
*
* @param string $originDir
* @param string $targetDir
* @param bool $relative
*
* @throws IOException If link can not be created.
*/
private function symlink($originDir, $targetDir, $relative = false)
{
if ($relative) {
$originDir = rtrim($this->filesystem->makePathRelative($originDir, dirname($targetDir)), DIRECTORY_SEPARATOR);
}
$this->filesystem->symlink($originDir, $targetDir);
if (!file_exists($targetDir)) {
throw new IOException(sprintf('Symbolic link "%s" was created but appears to be broken.', $targetDir), 0, null, $targetDir);
}
}

/**
* Copies origin to target.
*
* @param string $originDir
* @param string $targetDir
*
* @return string
*/
private function hardCopy($originDir, $targetDir)
{
if( is_file($originDir) ) {
$this->filesystem->mkdir(dirname($targetDir), 0777);
$this->filesystem->copy($originDir, $targetDir, false);
return self::METHOD_COPY;
}

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

return self::METHOD_COPY;
}


}
63 changes: 63 additions & 0 deletions Controller/EmitterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* EmitterController.php
* symfony3
* Date: 13.06.16
*/

namespace Avanzu\AdminThemeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class EmitterController extends Controller
{
/**
* @return \Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher|\Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher
*/
protected function getDispatcher()
{
return $this->get('event_dispatcher');
}

/**
* @param $eventName
*
* @return bool
*/
protected function hasListener($eventName)
{
return $this->getDispatcher()->hasListeners($eventName);
}

/**
* Will look for a method of the format "on<CamelizedEventName>" and call it with the event as argument.
*
*
* Then it will dispatch the event as normal via the event dispatcher.
*
* @param $eventName
* @param Event $event
*
* @return Event
*/
protected function triggerMethod($eventName, Event $event)
{
$method = sprintf('on%s', Container::camelize(str_replace('.', '_',$eventName)));

if( is_callable([$this, $method])) {
call_user_func_array([$this, $method], [$event]);
}

if( $event->isPropagationStopped() ){
return $event;
}

$this->getDispatcher()->dispatch($eventName, $event);

return $event;
}

}
13 changes: 13 additions & 0 deletions Controller/NavbarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function notificationsAction($max = 5)

}

/**
* @param int $max
*
* @return Response
*/
public function messagesAction($max = 5)
{

Expand All @@ -63,6 +68,11 @@ public function messagesAction($max = 5)
);
}

/**
* @param int $max
*
* @return Response
*/
public function tasksAction($max = 5)
{

Expand All @@ -80,6 +90,9 @@ public function tasksAction($max = 5)
);
}

/**
* @return Response
*/
public function userAction()
{

Expand Down
Loading

0 comments on commit a4e0391

Please sign in to comment.