Skip to content

Commit

Permalink
Merge pull request #1 from bankiru/feature/integration
Browse files Browse the repository at this point in the history
Pre-release integration tuning
  • Loading branch information
scaytrase authored Mar 28, 2017
2 parents 8a26bb6 + 7c8568e commit bae4b22
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 86 deletions.
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ php:
- 5.5
- 5.6
- 7
- 7.1
- nightly
- hhvm

env:
- SYMFONY_VERSION='2.8.*' deps='no'
- SYMFONY_VERSION='3.0.*' deps='no'
- SYMFONY_VERSION='3.1.*' deps='no'
- SYMFONY_VERSION='3.2.*' deps='no'
- SYMFONY_VERSION='~3.3@dev' deps='no'

matrix:
allow_failures:
- php: hhvm
- php: nightly
allow_failures:
- php: hhvm
- php: nightly

before_install:
- travis_retry composer self-update

install:
- composer require --no-update symfony/symfony=${SYMFONY_VERSION}
- if [ "$deps" = "no" ]; then composer --prefer-source install; fi;
- if [ "$deps" = "low" ]; then composer --prefer-source --prefer-lowest --prefer-stable update; fi;
- composer require --no-update symfony/symfony=${SYMFONY_VERSION}
- if [ "$deps" = "no" ]; then composer --prefer-source install; fi;
- if [ "$deps" = "low" ]; then composer --prefer-source --prefer-lowest --prefer-stable update; fi;

script:
- mkdir -p build
- phpunit --colors -c phpunit.xml --coverage-text
- vendor/bin/phpunit --colors -c phpunit.xml --coverage-text
6 changes: 6 additions & 0 deletions BankiruSeoEngineBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bankiru\Seo;

use Bankiru\Seo\DependencyInjection\BankiruSeoEngineExtension;
use Bankiru\Seo\DependencyInjection\Compiler\LinkGeneratorPass;
use Bankiru\Seo\DependencyInjection\Compiler\RouterPass;
use Bankiru\Seo\DependencyInjection\Compiler\SeoSourcePass;
Expand All @@ -19,4 +20,9 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new SlugNormalizerPass());
$container->addCompilerPass(new RouterPass());
}

public function getContainerExtension()
{
return new BankiruSeoEngineExtension();
}
}
2 changes: 1 addition & 1 deletion ConditionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function attach(TargetDefinitionInterface $target, $code);
/**
* @param mixed $object
*
* @return float
* @return float|null
*/
public function match($object);
}
15 changes: 15 additions & 0 deletions DependencyInjection/BankiruSeoEngineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ final class BankiruSeoEngineExtension extends Extension
/** {@inheritdoc} */
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

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

if (isset($config['target_repository'])) {
$container->setAlias('bankiru.seo.target_repository', $config['target_repository']);
}
if (isset($config['page_repository'])) {
$container->setAlias('bankiru.seo.page_repository', $config['page_repository']);
}
}

public function getAlias()
{
return 'bankiru_seo';
}
}
21 changes: 21 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Bankiru\Seo\DependencyInjection;

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

final class Configuration implements ConfigurationInterface
{
/** {@inheritdoc} */
public function getConfigTreeBuilder()
{
$builder = new TreeBuilder();
$root = $builder->root('bankiru_seo');

$root->children()->scalarNode('target_repository')->defaultNull();
$root->children()->scalarNode('page_repository')->defaultNull();

return $builder;
}
}
42 changes: 36 additions & 6 deletions Entity/AbstractCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,43 @@

namespace Bankiru\Seo\Entity;

use Bankiru\Seo\Exception\ConditionException;
use Bankiru\Seo\ConditionInterface;
use Bankiru\Seo\Exception\ConditionException;
use Bankiru\Seo\TargetDefinitionInterface;

abstract class AbstractCondition implements ConditionInterface
{
/**
* @var string
*/
protected $code;
private $code;

/**
* @var TargetDefinitionInterface
*/
protected $targetDefinition;
protected $target;

/**
* AbstractCondition constructor.
*
* @param string $code
* @param TargetDefinitionInterface $target
*/
public function __construct($code, TargetDefinitionInterface $target)
{
$this->code = $code;
$this->target = $target;
}

/** {@inheritdoc} */
public function attach(TargetDefinitionInterface $target, $code)
{
$this->code = $code;
$this->targetDefinition = $target;
$this->targetDefinition->setCondition($this->code, $this);
$this->code = $code;
$this->target = $target;
$this->target->setCondition($this->code, $this);
}

/** {@inheritdoc} */
public function match($object)
{
if (!$this->supports($object)) {
Expand All @@ -34,6 +48,22 @@ public function match($object)
return $this->doMatch($object);
}

/**
* @return string
*/
public function getCode()
{
return $this->code;
}

/**
* @return TargetDefinitionInterface
*/
public function getTarget()
{
return $this->target;
}

/**
* Checks whether the object is valid argument to perform matching
*
Expand Down
2 changes: 1 addition & 1 deletion Entity/PermissiveCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ protected function supports($object)
/** {@inheritdoc} */
protected function doMatch($object)
{
return 1;
return 0;
}
}
13 changes: 10 additions & 3 deletions Entity/TargetDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TargetDefinition implements TargetDefinitionInterface
*/
protected $conditions;
/** @var string */
protected $route;
private $route;

/**
* TargetDefinition constructor.
Expand All @@ -36,8 +36,15 @@ public function match(DestinationInterface $destination)
return null;
}

$conditions = $this->conditions->toArray();
foreach ($destination as $code => $item) {
if (!array_key_exists($code, $conditions)) {
$conditions[$code] = new PermissiveCondition($code, $this);
}
}

$result = 0;
foreach ($this->conditions as $code => $condition) {
foreach ($conditions as $code => $condition) {
$payload = $destination->resolve($code);
$score = $condition->match($payload);
if ($score === null) {
Expand Down Expand Up @@ -76,7 +83,7 @@ public function getCondition($code)
return $this->conditions->get($code);
}

return new PermissiveCondition();
return new PermissiveCondition($code, $this);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Integration/Local/CollectionSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private function createFilterIterator()
new \IteratorIterator($this->collection->getIterator()),
function ($element) {
foreach ($this->conditions as $condition) {
if (!$condition->match($element)) {
if (null === $condition->match($element)) {
return false;
}
}
Expand Down
24 changes: 9 additions & 15 deletions Listener/MasterSeoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

use Bankiru\Seo\DestinationInterface;
use Bankiru\Seo\DestinationMatcherInterface;
use Bankiru\Seo\Exception\MatchingException;
use Bankiru\Seo\Page\SeoPageInterface;

final class MasterSeoRequest
class MasterSeoRequest implements SeoRequestInterface
{
/** @var DestinationInterface */
private $destination;
Expand All @@ -26,11 +25,7 @@ public function __construct(DestinationMatcherInterface $matcher)
$this->matcher = $matcher;
}


/**
* @return DestinationInterface
* @throws \LogicException
*/
/** {@inheritdoc} */
public function getDestination()
{
if (null === $this->destination) {
Expand All @@ -40,19 +35,13 @@ public function getDestination()
return $this->destination;
}

/**
* @param DestinationInterface $destination
*/
/** {@inheritdoc} */
public function setDestination(DestinationInterface $destination)
{
$this->destination = $destination;
}

/**
* @return SeoPageInterface
* @throws \LogicException
* @throws MatchingException
*/
/** {@inheritdoc} */
public function getPage()
{
if (null === $this->page) {
Expand All @@ -61,4 +50,9 @@ public function getPage()

return $this->page;
}

public function getRenderedPage()
{
return $this->getPage();
}
}
16 changes: 11 additions & 5 deletions Listener/RequestDestinationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@

final class RequestDestinationFactory
{
public static function createFromRequest(Request $request)
public static function createFromRequest(Request $request, array $destination)
{
return new Destination(
$request->attributes->get('_route'),
$request->attributes->get('_route_params')
);
if (array_keys($destination) === range(0, count($destination) - 1)) {
$destination = array_combine($destination, $destination);
}

$attrs = [];
foreach ($destination as $seo => $attribute) {
$attrs[$seo] = $request->attributes->get($attribute);
}

return new Destination($request->attributes->get('_route'), $attrs);
}
}
33 changes: 33 additions & 0 deletions Listener/SeoRequestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Bankiru\Seo\Listener;

use Bankiru\Seo\DestinationInterface;
use Bankiru\Seo\Exception\MatchingException;
use Bankiru\Seo\Page\SeoPageInterface;

interface SeoRequestInterface
{
/**
* @return DestinationInterface
* @throws \LogicException
*/
public function getDestination();

/**
* @param DestinationInterface $destination
*/
public function setDestination(DestinationInterface $destination);

/**
* @return SeoPageInterface
* @throws MatchingException
*/
public function getPage();

/**
* @return SeoPageInterface
* @throws MatchingException
*/
public function getRenderedPage();
}
Loading

0 comments on commit bae4b22

Please sign in to comment.