Skip to content

Commit

Permalink
Saving work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
etki committed Nov 14, 2017
1 parent 64faf78 commit 6ad72a3
Show file tree
Hide file tree
Showing 16 changed files with 362 additions and 54 deletions.
18 changes: 11 additions & 7 deletions src/API/ConversionOptionsInterface.php
Expand Up @@ -2,20 +2,24 @@

namespace AmaTeam\Image\Projection\API;

use AmaTeam\Image\Projection\API\Conversion\FilterInterface;
use AmaTeam\Image\Projection\API\Framework\ProcessingOptionsInterface;
use AmaTeam\Image\Projection\API\Type\SourceOptionsInterface;
use AmaTeam\Image\Projection\API\Type\TargetOptionsInterface;

interface ConversionOptionsInterface
{
const INTERPOLATION_NONE = 'none';
const INTERPOLATION_BILINEAR = 'bilinear';
/**
* @return SourceOptionsInterface
*/
public function getSource();

/**
* @return string
* @return TargetOptionsInterface
*/
public function getInterpolationMode();
public function getTarget();

/**
* @return FilterInterface[]
* @return ProcessingOptionsInterface
*/
public function getFilters();
public function getProcessing();
}
19 changes: 19 additions & 0 deletions src/API/Framework/ProcessingOptionsInterface.php
@@ -0,0 +1,19 @@
<?php

namespace AmaTeam\Image\Projection\API\Framework;

use AmaTeam\Image\Projection\API\Conversion\ListenerInterface;
use AmaTeam\Image\Projection\API\Conversion\ProcessorInterface;

interface ProcessingOptionsInterface
{
/**
* @return ProcessorInterface[]
*/
public function getProcessors();

/**
* @return ListenerInterface[]
*/
public function getListeners();
}
10 changes: 10 additions & 0 deletions src/API/FrameworkInterface.php
Expand Up @@ -34,4 +34,14 @@ public function convertAll(
$format = Format::JPEG,
EncodingOptions $options = null
);

/**
* @return ConverterInterface
*/
public function getConverter();

/**
* @return RegistryInterface
*/
public function getRegistry();
}
43 changes: 43 additions & 0 deletions src/API/RegistryInterface.php
@@ -0,0 +1,43 @@
<?php

namespace AmaTeam\Image\Projection\API;

use AmaTeam\Image\Projection\API\Type\HandlerInterface;

interface RegistryInterface
{
/**
* @param string $type
* @param HandlerInterface $handler
* @return void
*/
public function register($type, HandlerInterface $handler);

/**
* @return string[]
*/
public function getRegisteredTypes();

/**
* @param string $type
* @return HandlerInterface
*/
public function getHandler($type);

/**
* Same as getHandler, but returns null instead of throwing
* exception.
*
* @param string $type
* @return HandlerInterface|null
*/
public function findHandler($type);

/**
* Returns correct type name by performing prefix-based search
*
* @param string $type
* @return string|null
*/
public function findType($type);
}
9 changes: 4 additions & 5 deletions src/API/Type/HandlerInterface.php
Expand Up @@ -2,7 +2,6 @@

namespace AmaTeam\Image\Projection\API\Type;

use AmaTeam\Image\Projection\API\ConversionOptionsInterface;
use AmaTeam\Image\Projection\API\SpecificationInterface;

interface HandlerInterface
Expand All @@ -11,23 +10,23 @@ interface HandlerInterface
* Creates new accessor for projection described by specification
*
* @param SpecificationInterface $specification
* @param ReaderOptionsInterface|null $options
* @param SourceOptionsInterface|null $options
* @return ReaderInterface
*/
public function createReader(
SpecificationInterface $specification,
ReaderOptionsInterface $options = null
SourceOptionsInterface $options = null
);

/**
* @param ReaderInterface $source
* @param SpecificationInterface $target
* @param ConversionOptionsInterface $options
* @param TargetOptionsInterface $options
* @return GeneratorInterface Iterator that emits tiles.
*/
public function createGenerator(
ReaderInterface $source,
SpecificationInterface $target,
ConversionOptionsInterface $options = null
TargetOptionsInterface $options = null
);
}
9 changes: 9 additions & 0 deletions src/API/Type/Interpolation.php
@@ -0,0 +1,9 @@
<?php

namespace AmaTeam\Image\Projection\API\Type;

class Interpolation
{
const NONE = 'none';
const BILINEAR = 'bilinear';
}
Expand Up @@ -2,7 +2,7 @@

namespace AmaTeam\Image\Projection\API\Type;

interface ReaderOptionsInterface
interface SourceOptionsInterface
{
/**
* @return string
Expand Down
32 changes: 32 additions & 0 deletions src/API/Type/TargetOptionsInterface.php
@@ -0,0 +1,32 @@
<?php

namespace AmaTeam\Image\Projection\API\Type;

use AmaTeam\Image\Projection\API\Conversion\FilterInterface;

interface TargetOptionsInterface
{
/**
* @return FilterInterface[]
*/
public function getFilters();

/**
* @return string
*/
public function getFormat();

/**
* Tile generation quality, 0.0...1.0 (JPEG only)
*
* @return float
*/
public function getQuality();

/**
* Tile compression level, 0.0...1.0 (PNG only)
*
* @return float
*/
public function getCompression();
}
9 changes: 5 additions & 4 deletions src/Framework.php
Expand Up @@ -5,6 +5,7 @@
use AmaTeam\Image\Projection\API\ConversionInterface;
use AmaTeam\Image\Projection\API\ConverterInterface;
use AmaTeam\Image\Projection\API\FrameworkInterface;
use AmaTeam\Image\Projection\API\RegistryInterface;
use AmaTeam\Image\Projection\API\SpecificationInterface;
use AmaTeam\Image\Projection\Framework\Converter;
use AmaTeam\Image\Projection\Conversion\Listener\SaveListener;
Expand All @@ -18,7 +19,7 @@
class Framework implements FrameworkInterface
{
/**
* @var Registry
* @var RegistryInterface
*/
private $registry;
/**
Expand All @@ -31,11 +32,11 @@ class Framework implements FrameworkInterface
private $converter;

/**
* @param Registry $registry
* @param RegistryInterface $registry
* @param LoggerInterface|null $logger
*/
public function __construct(
Registry $registry = null,
RegistryInterface $registry = null,
LoggerInterface $logger = null
) {
$logger = $logger ?: new NullLogger();
Expand Down Expand Up @@ -144,7 +145,7 @@ public function getConverter()
}

/**
* @return Registry
* @return RegistryInterface
*/
public function getRegistry()
{
Expand Down
58 changes: 41 additions & 17 deletions src/Framework/ConversionOptions.php
Expand Up @@ -2,53 +2,77 @@

namespace AmaTeam\Image\Projection\Framework;

use AmaTeam\Image\Projection\API\Conversion\FilterInterface;
use AmaTeam\Image\Projection\API\ConversionOptionsInterface;
use AmaTeam\Image\Projection\API\Framework\ProcessingOptionsInterface;
use AmaTeam\Image\Projection\API\Type\SourceOptionsInterface;
use AmaTeam\Image\Projection\API\Type\TargetOptionsInterface;

class ConversionOptions implements ConversionOptionsInterface
{
/**
* @var string
* @var SourceOptionsInterface
*/
private $interpolationMode = self::INTERPOLATION_BILINEAR;
private $source;
/**
* @var FilterInterface[]
* @var TargetOptionsInterface
*/
private $filters = [];
private $target;
/**
* @var ProcessingOptionsInterface
*/
private $processing;

/**
* @return SourceOptionsInterface
*/
public function getSource()
{
return $this->source;
}

/**
* @param SourceOptionsInterface $source
* @return $this
*/
public function setSource($source)
{
$this->source = $source;
return $this;
}

/**
* @return string
* @return TargetOptionsInterface
*/
public function getInterpolationMode()
public function getTarget()
{
return $this->interpolationMode;
return $this->target;
}

/**
* @param string $interpolationMode
* @param TargetOptionsInterface $target
* @return $this
*/
public function setInterpolationMode($interpolationMode)
public function setTarget($target)
{
$this->interpolationMode = $interpolationMode;
$this->target = $target;
return $this;
}

/**
* @return FilterInterface[]
* @return ProcessingOptionsInterface
*/
public function getFilters()
public function getProcessing()
{
return $this->filters;
return $this->processing;
}

/**
* @param FilterInterface[] $filters
* @param ProcessingOptionsInterface $processing
* @return $this
*/
public function setFilters($filters)
public function setProcessing($processing)
{
$this->filters = $filters;
$this->processing = $processing;
return $this;
}
}
14 changes: 9 additions & 5 deletions src/Framework/Converter.php
Expand Up @@ -47,7 +47,7 @@ public function createConversions(
$context = ['source' => $source, 'targets' => $targets];
$message = 'Converting {source} to targets {targets}';
$this->logger->debug($message, $context);
$reader = $this->getReader($source);
$reader = $this->getReader($source, $options);
$pipelines = [];
foreach ($targets as $target) {
$pipelines[] = $this
Expand All @@ -71,21 +71,25 @@ public function createConversion(
) {
$context = ['source' => $source, 'target' => $target];
$message = 'Converting {source} to target {target}';
$options = $options ?: new ConversionOptions();
$this->logger->debug($message, $context);
$reader = $this->getReader($source);
$reader = $this->getReader($source, $options);
return $this->instantiateConversion($reader, $target, $options);
}

/**
* @param SpecificationInterface $source
* @param ConversionOptionsInterface $options
* @return ReaderInterface
*/
private function getReader(SpecificationInterface $source)
{
private function getReader(
SpecificationInterface $source,
ConversionOptionsInterface $options = null
) {
return $this
->registry
->getHandler($source->getType())
->createReader($source);
->createReader($source, $options);
}

/**
Expand Down

0 comments on commit 6ad72a3

Please sign in to comment.