Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosister committed Jul 31, 2015
2 parents dbd7398 + 3ce69e0 commit 896b62c
Show file tree
Hide file tree
Showing 44 changed files with 214 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
node_modules
bin
phpunit.xml
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Patch Manager

A php library to manage PATCH requests in a standardized (and elegant) way

### Be careful!!!

*From version 0.3 namespace will change from PatchManager\\... to Cypress\\PatchManager\\...*

## Install

Install with composer

``` json
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"autoload": {
"psr-4": {
"PatchManager\\": "src/PatchManager/",
"PatchManager\\Tests\\": "tests/PatchManager/"
"Cypress\\PatchManager\\": "src/PatchManager/",
"Cypress\\PatchManager\\Tests\\": "tests/PatchManager/"
}
},
"license": "LGPL-3.0+",
Expand Down
10 changes: 5 additions & 5 deletions examples/data_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

require_once __DIR__.'/../vendor/autoload.php';

use PatchManager\Request\Operations;
use PatchManager\OperationMatcher;
use PatchManager\Handler\DataHandler;
use PatchManager\PatchManager;
use Cypress\PatchManager\Request\Operations;
use Cypress\PatchManager\OperationMatcher;
use Cypress\PatchManager\Handler\DataHandler;
use Cypress\PatchManager\PatchManager;

class Subject implements \PatchManager\Patchable
class Subject implements \Cypress\PatchManager\Patchable
{
private $a = 1;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Bundle\DependencyInjection;
namespace Cypress\PatchManager\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Bundle\DependencyInjection;
namespace Cypress\PatchManager\Bundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Bundle\DependencyInjection;
namespace Cypress\PatchManager\Bundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
4 changes: 2 additions & 2 deletions src/PatchManager/Bundle/PatchManagerBundle.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace PatchManager\Bundle;
namespace Cypress\PatchManager\Bundle;

use PatchManager\Bundle\DependencyInjection\PatchManagerCompilerPass;
use Cypress\PatchManager\Bundle\DependencyInjection\PatchManagerCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace PatchManager\Bundle\RequestAdapter;
namespace Cypress\PatchManager\Bundle\RequestAdapter;

use PatchManager\Request\Adapter;
use PatchManager\Request\Operations;
use Cypress\PatchManager\Request\Adapter;
use Cypress\PatchManager\Request\Operations;
use Symfony\Component\HttpFoundation\RequestStack;

class RequestStackAdapter implements Adapter
Expand Down
2 changes: 1 addition & 1 deletion src/PatchManager/Bundle/Resources/config/handlers/data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="patch_manager.handler.data" public="false" class="PatchManager\Handler\DataHandler" />
<service id="patch_manager.handler.data" public="false" class="Cypress\PatchManager\Handler\DataHandler" />
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="patch_manager.handler.data" public="false" class="PatchManager\Handler\DataDoctrineHandler" />
<service id="patch_manager.handler.data" public="false" class="Cypress\PatchManager\Handler\DataDoctrineHandler" />
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="patch_manager.handler.state_machine" public="false" class="PatchManager\Handler\FiniteHandler">
<service id="patch_manager.handler.state_machine" public="false" class="Cypress\PatchManager\Handler\FiniteHandler">
<argument type="service" id="finite.factory" />
</service>
</services>
Expand Down
8 changes: 4 additions & 4 deletions src/PatchManager/Bundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="patch_manager.request_adapter" class="PatchManager\Bundle\RequestAdapter\RequestStackAdapter">
<service id="patch_manager.request_adapter" class="Cypress\PatchManager\Bundle\RequestAdapter\RequestStackAdapter">
<argument type="service" id="request_stack" />
</service>
<service id="patch_manager.operations" public="false" class="PatchManager\Request\Operations">
<service id="patch_manager.operations" public="false" class="Cypress\PatchManager\Request\Operations">
<configurator service="patch_manager.request_adapter" method="setRequestBody" />
</service>
<service id="patch_manager.operation_matcher" public="false" class="PatchManager\OperationMatcher">
<service id="patch_manager.operation_matcher" public="false" class="Cypress\PatchManager\OperationMatcher">
<argument type="service" id="patch_manager.operations" />
</service>
<service id="patch_manager" public="true" class="PatchManager\PatchManager">
<service id="patch_manager" public="true" class="Cypress\PatchManager\PatchManager">
<argument type="service" id="patch_manager.operation_matcher" />
<argument>%patch_manager.strict_mode%</argument>
</service>
Expand Down
6 changes: 3 additions & 3 deletions src/PatchManager/Event/PatchManagerEvent.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace PatchManager\Event;
namespace Cypress\PatchManager\Event;

use PatchManager\MatchedPatchOperation;
use PatchManager\Patchable;
use Cypress\PatchManager\MatchedPatchOperation;
use Cypress\PatchManager\Patchable;
use Symfony\Component\EventDispatcher\Event;

class PatchManagerEvent extends Event
Expand Down
2 changes: 1 addition & 1 deletion src/PatchManager/Event/PatchManagerEvents.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Event;
namespace Cypress\PatchManager\Event;

final class PatchManagerEvents
{
Expand Down
2 changes: 1 addition & 1 deletion src/PatchManager/Exception/HandlerNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace PatchManager\Exception;
namespace Cypress\PatchManager\Exception;


use Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/PatchManager/Exception/InvalidJsonRequestContent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Exception;
namespace Cypress\PatchManager\Exception;

class InvalidJsonRequestContent extends PatchManagerException
{
Expand Down
2 changes: 1 addition & 1 deletion src/PatchManager/Exception/MissingOperationNameRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Exception;
namespace Cypress\PatchManager\Exception;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/PatchManager/Exception/MissingOperationRequest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace PatchManager\Exception;
namespace Cypress\PatchManager\Exception;


class MissingOperationRequest extends PatchManagerException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Exception;
namespace Cypress\PatchManager\Exception;

class NonExistentOperationException extends PatchManagerException
{
Expand Down
2 changes: 1 addition & 1 deletion src/PatchManager/Exception/PatchManagerException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager\Exception;
namespace Cypress\PatchManager\Exception;

class PatchManagerException extends \Exception
{
Expand Down
4 changes: 2 additions & 2 deletions src/PatchManager/Handler/DataDoctrineHandler.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace PatchManager\Handler;
namespace Cypress\PatchManager\Handler;

use Doctrine\ORM\EntityManagerInterface;
use PatchManager\OperationData;
use Cypress\PatchManager\OperationData;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Doctrine\Common\Persistence\Proxy;

Expand Down
17 changes: 14 additions & 3 deletions src/PatchManager/Handler/DataHandler.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace PatchManager\Handler;
namespace Cypress\PatchManager\Handler;

use PatchManager\OperationData;
use PatchManager\PatchOperationHandler;
use Cypress\PatchManager\OperationData;
use Cypress\PatchManager\PatchOperationHandler;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\PropertyAccess\PropertyAccessor;

Expand Down Expand Up @@ -54,4 +54,15 @@ public function configureOptions(OptionsResolver $optionsResolver)
{
$optionsResolver->setRequired(array('property', 'value'));
}

/**
* wether the handler is able to handle the given subject
*
* @param $subject
* @return bool
*/
public function canHandle($subject)
{
return true;
}
}
17 changes: 14 additions & 3 deletions src/PatchManager/Handler/FiniteHandler.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace PatchManager\Handler;
namespace Cypress\PatchManager\Handler;

use Finite\Factory\FactoryInterface;
use PatchManager\OperationData;
use PatchManager\PatchOperationHandler;
use Cypress\PatchManager\OperationData;
use Cypress\PatchManager\PatchOperationHandler;
use Symfony\Component\OptionsResolver\OptionsResolver;

class FiniteHandler implements PatchOperationHandler
Expand Down Expand Up @@ -60,4 +60,15 @@ public function configureOptions(OptionsResolver $optionsResolver)
->setDefined(array('check'))
->setDefaults(array('check' => false));
}

/**
* wether the handler is able to handle the given subject
*
* @param $subject
* @return bool
*/
public function canHandle($subject)
{
return true;
}
}
2 changes: 1 addition & 1 deletion src/PatchManager/MatchedPatchOperation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PatchManager;
namespace Cypress\PatchManager;

use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down
4 changes: 2 additions & 2 deletions src/PatchManager/OperationData.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php


namespace PatchManager;
namespace Cypress\PatchManager;

use PatchManager\Request\Operations;
use Cypress\PatchManager\Request\Operations;
use PhpCollection\Map;
use PhpCollection\Sequence;

Expand Down
28 changes: 21 additions & 7 deletions src/PatchManager/OperationMatcher.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

namespace PatchManager;
namespace Cypress\PatchManager;

use PatchManager\Request\Operations;
use Cypress\PatchManager\Request\Operations;
use PhpCollection\Sequence;
use PhpOption\Option;

/**
* Match the correct handlers based on actual operations
Expand Down Expand Up @@ -38,35 +39,48 @@ public function addHandler(PatchOperationHandler $handler)
}

/**
* @param $subject
*
* @return Sequence
*
* @throws Exception\MissingOperationNameRequest
* @throws Exception\MissingOperationRequest
*/
public function getMatchedOperations()
public function getMatchedOperations($subject)
{
$handlers = $this->handlers;
return $this->operations
->all()
->foldLeft(
new Sequence(),
function (Sequence $matchedOperations, array $operationData) use ($handlers) {
function (Sequence $matchedOperations, array $operationData) use ($handlers, $subject) {
/** @var Option $handler */
$handler = $handlers->find(function (PatchOperationHandler $handler) use ($operationData) {
return $operationData[Operations::OP_KEY_NAME] === $handler->getName();
});
if ($handler->isDefined()) {
$matchedOperations->add(MatchedPatchOperation::create($operationData, $handler->get()));
/** @var PatchOperationHandler $patchOperationHandler */
$patchOperationHandler = $handler->get();
if ($patchOperationHandler->canHandle($subject)) {
$matchedOperations->add(MatchedPatchOperation::create($operationData, $handler->get()));
}
}
return $matchedOperations;
}
);
}

/**
* @param $subject
*
* @return Sequence
*
* @throws Exception\MissingOperationNameRequest
* @throws Exception\MissingOperationRequest
*/
public function getUnmatchedOperations()
public function getUnmatchedOperations($subject)
{
$matchedOperations = $this->getMatchedOperations();
$matchedOperations = $this->getMatchedOperations($subject);
return $this->operations
->all()
->filter(function (array $operationData) use ($matchedOperations) {
Expand Down
Loading

0 comments on commit 896b62c

Please sign in to comment.