-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
1,996 additions
and
1,284 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
DependencyInjection/CompilerPass/ImageProviderCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.