Skip to content

Commit

Permalink
new version changes
Browse files Browse the repository at this point in the history
  • Loading branch information
portey committed Oct 31, 2016
1 parent 68bca1d commit 62b33ea
Show file tree
Hide file tree
Showing 58 changed files with 1,996 additions and 1,284 deletions.
9 changes: 0 additions & 9 deletions ApiImagesBundle.php

This file was deleted.

42 changes: 42 additions & 0 deletions Controller/ImageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Youshido\ImagesBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Youshido\ImagesBundle\DTO\PathableDTO;
use Youshido\ImagesBundle\ValueObject\ResizeConfig;

class ImageController extends Controller
{

/**
* @Route("/media/cache/{mode}/{width}x{height}/{path}", name="images.resize", requirements={"path"=".+"})
*
* @param $mode
* @param $width
* @param $height
* @param $path
*
* @return Response
*
* @throws \Exception
*/
public function resizeAction($mode, $width, $height, $path) : Response
{
try {
$resizer = $this->get('api_images.resizer');

$pathable = new PathableDTO($path);
$config = new ResizeConfig($width, $height, $mode);

$resizer->resize($pathable, $config);

return new RedirectResponse($resizer->getPathResolver()->resolveWebResizablePath($config, $pathable), 301);
} catch (\Exception $e) {
throw $this->createNotFoundException();
}
}
}
48 changes: 48 additions & 0 deletions DTO/ImageDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Date: 11.10.16
*
* @author Portey Vasil <[email protected]>
*/

namespace Youshido\ImagesBundle\DTO;

use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;

class ImageDTO
{

/**
* @Assert\NotNull()
* @Assert\Image(maxSize="5M")
*/
private $uploadedFile;

public function __construct(UploadedFile $uploadedFile)
{
$this->setUploadedFile($uploadedFile);
}

/**
* @return mixed
*/
public function getUploadedFile()
{
return $this->uploadedFile;
}

/**
* @param mixed $uploadedFile
*
* @return ImageDTO
*/
public function setUploadedFile(UploadedFile $uploadedFile)
{
$this->uploadedFile = $uploadedFile;

return $this;
}


}
30 changes: 30 additions & 0 deletions DTO/PathableDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Date: 12.10.16
*
* @author Portey Vasil <[email protected]>
*/

namespace Youshido\ImagesBundle\DTO;


use Youshido\ImagesBundle\Document\Interfaces\PathableInterface;

class PathableDTO implements PathableInterface
{

private $path;

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

/**
* @return string
*/
public function getPath()
{
return $this->path;
}
}
30 changes: 0 additions & 30 deletions DependencyInjection/ApiImagesExtension.php

This file was deleted.

48 changes: 48 additions & 0 deletions DependencyInjection/CompilerPass/ImageProviderCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Date: 21.10.16
*
* @author Portey Vasil <[email protected]>
*/

namespace Youshido\ImagesBundle\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Youshido\ImagesBundle\Services\Provider\ODMProvider;
use Youshido\ImagesBundle\Services\Provider\ORMProvider;

class ImageProviderCompilerPass implements CompilerPassInterface
{

/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$definition = new Definition();
$db = $container->getParameter('api_images.config.platform');

switch ($db) {
case 'orm':
$definition->setClass(ORMProvider::class);
$definition->addArgument(new Reference('doctrine.orm.entity_manager'));
break;

case 'odm':
$definition->setClass(ODMProvider::class);
$definition->addArgument(new Reference('doctrine_mongodb.odm.document_manager'));
break;
}

$definition->addArgument(new Reference('validator'));
$definition->addArgument(new Reference('api_images.loader'));
$definition->addArgument(new Reference('request_stack'));

$container->setDefinition('api_images.provider', $definition);
}
}
22 changes: 15 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Youshido\ApiImagesBundle\DependencyInjection;
namespace Youshido\ImagesBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
*/
class Configuration implements ConfigurationInterface
{
Expand All @@ -18,13 +18,21 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('api_images');
$rootNode = $treeBuilder->root('images');

$rootNode
->children()
->scalarNode('image_model')
->isRequired()
->cannotBeEmpty()
->scalarNode('web_root')->isRequired()->cannotBeEmpty()->end()
->scalarNode('path_prefix')->cannotBeEmpty()->defaultValue('uploads/images')->end()
->enumNode('platform')->values(['odm', 'orm'])->defaultValue('orm')->cannotBeEmpty()->end()
->enumNode('driver')->values(['gd', 'imagick', 'gmagick'])->defaultValue('gd')->cannotBeEmpty()->end()
->arrayNode('routing')
->addDefaultsIfNotSet()
->canBeUnset()
->children()
->scalarNode('host')->defaultNull()->end()
->scalarNode('scheme')->defaultNull()->end()
->end()
->end()
->end();

Expand Down
41 changes: 41 additions & 0 deletions DependencyInjection/ImagesExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Youshido\ImagesBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class ImagesExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$this->setContainerParam($container, 'web_root', $config['web_root']);
$this->setContainerParam($container, 'path_prefix', $config['path_prefix']);
$this->setContainerParam($container, 'driver', $config['driver']);
$this->setContainerParam($container, 'platform', $config['platform']);

$this->setContainerParam($container, 'host', $config['routing']['host']);
$this->setContainerParam($container, 'scheme', $config['routing']['scheme']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}

private function setContainerParam(ContainerBuilder $container, $parameter, $value)
{
$container->setParameter(sprintf('api_images.config.%s', $parameter), $value);
}
}
Loading

0 comments on commit 62b33ea

Please sign in to comment.