mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Sequence] Remove sequence component and bundle
This commit is contained in:
parent
7d3a4f8240
commit
54e8eae415
56 changed files with 19 additions and 1816 deletions
|
|
@ -7,6 +7,15 @@ UPGRADE
|
|||
|
||||
* Renamed configuration option `sylius_channel.fake_channel_support` to `sylius_channel.debug`
|
||||
|
||||
### Order and OrderBundle
|
||||
|
||||
* Added ``OrderSequence`` model to keep current order index
|
||||
* Added ``OrderNumberGenerator`` to generate number for new orders
|
||||
|
||||
### Sequence and SequenceBundle
|
||||
|
||||
* Removed ``Sequence`` component and ``SequenceBundle``
|
||||
|
||||
## From 0.18 to 0.19.x
|
||||
|
||||
### Core and CoreBundle
|
||||
|
|
|
|||
|
|
@ -148,8 +148,6 @@
|
|||
"sylius/resource": "self.version",
|
||||
"sylius/resource-bundle": "self.version",
|
||||
"sylius/search-bundle": "self.version",
|
||||
"sylius/sequence": "self.version",
|
||||
"sylius/sequence-bundle": "self.version",
|
||||
"sylius/settings-bundle": "self.version",
|
||||
"sylius/shipping": "self.version",
|
||||
"sylius/shipping-bundle": "self.version",
|
||||
|
|
|
|||
15
composer.lock
generated
15
composer.lock
generated
|
|
@ -4,8 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "3933e4fcbb56494b6df69eee8a0022b2",
|
||||
"content-hash": "66eedeb56cc54d23081335ddf8ca3b7c",
|
||||
"hash": "4b3521f709bb0a1eabbc87d7c3f8c0b4",
|
||||
"packages": [
|
||||
{
|
||||
"name": "behat/transliterator",
|
||||
|
|
@ -1839,7 +1838,6 @@
|
|||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"abandoned": "guzzlehttp/guzzle",
|
||||
"time": "2015-03-18 18:23:50"
|
||||
},
|
||||
{
|
||||
|
|
@ -6082,9 +6080,9 @@
|
|||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"name": "Johannes M. Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh",
|
||||
"homepage": "http://jmsyst.com",
|
||||
"role": "Developer of wrapped JMSSerializerBundle"
|
||||
}
|
||||
],
|
||||
|
|
@ -8759,7 +8757,7 @@
|
|||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "William Durand",
|
||||
"name": "William DURAND",
|
||||
"email": "william.durand1@gmail.com",
|
||||
"homepage": "http://www.willdurand.fr"
|
||||
}
|
||||
|
|
@ -10076,7 +10074,7 @@
|
|||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Lakion/ApiTestCase/zipball/c4d37eccbaa49f06a317d22198649517627ed599",
|
||||
"url": "https://api.github.com/repos/Lakion/ApiTestCase/zipball/171e6b7c00bc0d5b56edfc68f1a1d91f48c60850",
|
||||
"reference": "c4d37eccbaa49f06a317d22198649517627ed599",
|
||||
"shasum": ""
|
||||
},
|
||||
|
|
@ -10668,8 +10666,7 @@
|
|||
"authors": [
|
||||
{
|
||||
"name": "Chris Boulton",
|
||||
"homepage": "http://github.com/chrisboulton",
|
||||
"role": "Original developer"
|
||||
"homepage": "http://github.com/chrisboulton"
|
||||
}
|
||||
],
|
||||
"description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@ This interface should be implemented by model representing a single Order.
|
|||
|
||||
.. note::
|
||||
This interface extends :ref:`component_resource_model_timestampable-interface`, :ref:`component_resource_model_timestampable-interface`,
|
||||
:ref:`component_order_model_adjustable-interface`, :ref:`component_order_model_comment-aware-interface`
|
||||
and :ref:`component_sequence_model_sequence-subject-interface`.
|
||||
:ref:`component_order_model_adjustable-interface` and :ref:`component_order_model_comment-aware-interface`
|
||||
|
||||
For more detailed information go to `Sylius API OrderInterface`_.
|
||||
|
||||
|
|
@ -148,8 +147,7 @@ In order to decouple from storage that provides recently completed orders or che
|
|||
you should create repository class which implements this interface.
|
||||
|
||||
.. note::
|
||||
This interface extends the :ref:`component_resource_repository_repository-interface` and
|
||||
the :ref:`component_sequence_repository_hash-subject-repository-interface`.
|
||||
This interface extends the :ref:`component_resource_repository_repository-interface`.
|
||||
|
||||
For more detailed information about the interface go to `Sylius API OrderRepositoryInterface`_.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
Basic Usage
|
||||
===========
|
||||
|
||||
In order to benefit from the component's features at first you need to create a basic class that will implement
|
||||
the :ref:`component_sequence_model_sequence-subject-interface`. Let's assume that you would like to generate identifiers for orders in your system. Your **Order** class therefore will implement this interface
|
||||
to have and ability to be a subject of sequence automatic generation by your services.
|
||||
|
||||
SequenceSubjectInterface
|
||||
------------------------
|
||||
|
||||
Let's see how an exemplary class implementing **SequenceSubjectInterface** should look like.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Entity\Order;
|
||||
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
|
||||
class Order implements SequenceSubjectInterface
|
||||
{
|
||||
const SEQUENCE_TYPE = 'order';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $number;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSequenceType()
|
||||
{
|
||||
return self::SEQUENCE_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNumber()
|
||||
{
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setNumber($number)
|
||||
{
|
||||
$this->number = $number;
|
||||
}
|
||||
}
|
||||
|
||||
.. _component_sequence_number_sequential-generator-usage:
|
||||
|
||||
Let's now see how we can use an exemplary generator:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Sylius\Component\Sequence\Model\Sequence;
|
||||
use Sylius\Component\Sequence\Number\SequentialGenerator;
|
||||
use AppBundle\Entity\Order;
|
||||
|
||||
// Prepare an object for the sequence you are going to generate, that will store its type.
|
||||
$sequence = new Sequence('order');
|
||||
|
||||
$subject = new Order();
|
||||
$anotherSubject = new Order();
|
||||
|
||||
// Instantiate the generator that will generate sequences of length 4 starting from 0077.
|
||||
$generator = new SequentialGenerator(4, 77);
|
||||
|
||||
$generator->generate($subject, $sequence);
|
||||
$generator->generate($anotherSubject, $sequence);
|
||||
|
||||
$subject->getNumber(); // returns '0077'
|
||||
$anotherSubject->getNumber(); // returns '0078'
|
||||
|
||||
.. hint::
|
||||
|
||||
You can read more about each of the available generators in the :doc:`generators` chapter.
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
Generators
|
||||
==========
|
||||
|
||||
.. _component_sequence_number_abstract-generator:
|
||||
|
||||
AbstractGenerator
|
||||
-----------------
|
||||
|
||||
A custom generator model should extend this class in order to generate sequences
|
||||
on a given object that implements the :ref:`component_sequence_model_sequence-subject-interface`.
|
||||
|
||||
.. note::
|
||||
This class implements the :ref:`component_sequence_number_generator-interface`.
|
||||
|
||||
For more detailed information go to `Sylius API AbstractGenerator`_.
|
||||
|
||||
.. _Sylius API AbstractGenerator: http://api.sylius.org/Sylius/Component/Sequence/Number/AbstractGenerator.html
|
||||
|
||||
.. _component_sequence_number_sequential-generator:
|
||||
|
||||
SequentialGenerator
|
||||
-------------------
|
||||
|
||||
This class is a default order number generator.
|
||||
|
||||
+--------------------+------------------------------+
|
||||
| Property | Description |
|
||||
+====================+==============================+
|
||||
| numberLength | Order number max length |
|
||||
+--------------------+------------------------------+
|
||||
| startNumber | The sequence start number |
|
||||
+--------------------+------------------------------+
|
||||
|
||||
Below you can see a snippet on how to use it:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
// Instantiate the generator that will generate sequences of length 4 starting from 0077.
|
||||
$generator = new SequentialGenerator(4, 77);
|
||||
|
||||
// And use it on subjects that implement the SequenceSubjectInterface
|
||||
$generator->generate($subject, $sequence); // generates '0077'
|
||||
$generator->generate($anotherSubject, $sequence); // generates '0078'
|
||||
|
||||
.. note::
|
||||
This generator implements the :ref:`component_sequence_number_generator-interface`
|
||||
and extends the :ref:`component_sequence_number_abstract-generator`.
|
||||
|
||||
For more detailed information go to `Sylius API SequentialGenerator`_.
|
||||
|
||||
.. _Sylius API SequentialGenerator: http://api.sylius.org/Sylius/Component/Sequence/Number/SequentialGenerator.html
|
||||
|
||||
.. _component_sequence_number_hash-generator:
|
||||
|
||||
HashGenerator
|
||||
-------------
|
||||
|
||||
This class generates hash numbers similar to the Amazon order identifiers (e.g. 105-3958356-3707476)
|
||||
and also random hashed segments of a given length.
|
||||
|
||||
Below you can see a snippet on how to use it:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
$subject = new Order();
|
||||
$repository = new InMemoryRepository();
|
||||
|
||||
// Instantiate the generator that will generate a 3 by 7 by 7 digits number.
|
||||
$generator = new HashGenerator($repository);
|
||||
|
||||
$index = /** index of the sequence **/
|
||||
$generator->generateNumber($index, $subject);
|
||||
|
||||
$subject->getNumber(); // returns randomized sequence of format 'xxx-xxxxxxx-xxxxxxx'
|
||||
|
||||
.. note::
|
||||
This generator implements the :ref:`component_sequence_number_generator-interface`
|
||||
and extends the :ref:`component_sequence_number_abstract-generator`.
|
||||
|
||||
For more detailed information go to `Sylius API HashGenerator`_.
|
||||
|
||||
.. _Sylius API HashGenerator: http://api.sylius.org/Sylius/Component/Sequence/Number/HashGenerator.html
|
||||
|
||||
.. _component_sequence_registry_generator-registry:
|
||||
|
||||
GeneratorRegistry
|
||||
-----------------
|
||||
|
||||
It returns the generator used for a given entity.
|
||||
|
||||
.. note::
|
||||
This service extends the :ref:`component_registry_service-registry`.
|
||||
|
||||
For more detailed information go to `Sylius API GeneratorRegistry`_.
|
||||
|
||||
.. caution::
|
||||
Throws :ref:`component_registry_non-existing-service-exception`.
|
||||
|
||||
.. _Sylius API GeneratorRegistry: http://api.sylius.org/Sylius/Component/Sequence/Registry/GeneratorRegistry.html
|
||||
|
||||
.. _component_sequence_generator_non-existing-generator-exception:
|
||||
|
||||
NonExistingGeneratorException
|
||||
-----------------------------
|
||||
|
||||
This exception is thrown when your are trying to get a generator that does not exist in your system.
|
||||
|
||||
.. note:: This exception extends the `\\InvalidArgumentException`_.
|
||||
|
||||
.. _\\InvalidArgumentException: http://php.net/manual/en/class.invalidargumentexception.php
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
Sequence
|
||||
========
|
||||
|
||||
Component for generating number/hash sequences in PHP.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation
|
||||
basic_usage
|
||||
models
|
||||
interfaces
|
||||
generators
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
Installation
|
||||
============
|
||||
|
||||
You can install the component in 2 different ways:
|
||||
|
||||
* :doc:`Install it via Composer </components/general/using_components>` (``sylius/sequence`` on `Packagist`_);
|
||||
* Use the official Git repository (https://github.com/Sylius/Sequence).
|
||||
|
||||
.. include:: /components/require_autoload.rst.inc
|
||||
|
||||
.. _Packagist: https://packagist.org/packages/sylius/sequence
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
Interfaces
|
||||
==========
|
||||
|
||||
Model Interfaces
|
||||
----------------
|
||||
|
||||
.. _component_sequence_model_sequence-interface:
|
||||
|
||||
SequenceInterface
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
This interface should be implemented by models representing a **Sequence**.
|
||||
|
||||
.. note::
|
||||
|
||||
You will find more information about this interface in `Sylius API SequenceInterface`_.
|
||||
|
||||
.. _Sylius API SequenceInterface: http://api.sylius.org/Sylius/Component/Sequence/Model/SequenceInterface.html
|
||||
|
||||
.. _component_sequence_model_sequence-subject-interface:
|
||||
|
||||
SequenceSubjectInterface
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
To characterize an object with attributes and options from a sequence, the object class needs to implement the ``SequenceSubjectInterface``.
|
||||
|
||||
.. note::
|
||||
|
||||
You will find more information about this interface in `Sylius API SequenceSubjectInterface`_.
|
||||
|
||||
.. _Sylius API SequenceSubjectInterface: http://api.sylius.org/Sylius/Component/Sequence/Model/SequenceSubjectInterface.html
|
||||
|
||||
Service Interfaces
|
||||
------------------
|
||||
|
||||
.. _component_sequence_number_generator-interface:
|
||||
|
||||
GeneratorInterface
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This interface gives a possibility to generate and apply next available number for a given subject.
|
||||
|
||||
.. note::
|
||||
|
||||
You will find more information about this interface in `Sylius API GeneratorInterface`_.
|
||||
|
||||
.. _Sylius API GeneratorInterface: http://api.sylius.org/Sylius/Component/Sequence/Number/GeneratorInterface.html
|
||||
|
||||
.. _component_sequence_repository_hash-subject-repository-interface:
|
||||
|
||||
HashSubjectRepositoryInterface
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Repository interface for model which needs number uniqueness check before applying. It provides a method ``isNumberUsed()``.
|
||||
|
||||
.. note::
|
||||
|
||||
You will find more information about this interface in `Sylius API HashSubjectRepositoryInterface`_.
|
||||
|
||||
.. _Sylius API HashSubjectRepositoryInterface: http://api.sylius.org/Sylius/Component/Sequence/Repository/HashSubjectRepositoryInterface.html
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
Models
|
||||
======
|
||||
|
||||
.. _component_sequence_model_sequence:
|
||||
|
||||
Sequence
|
||||
--------
|
||||
|
||||
**Sequence** is a generated set of numbers and/or letters stored on a model. They may be useful for example as order or customer identifiers.
|
||||
|
||||
+------------+------------------------------+
|
||||
| Property | Description |
|
||||
+============+==============================+
|
||||
| id | Unique id of the sequence |
|
||||
+------------+------------------------------+
|
||||
| index | The sequence's index |
|
||||
+------------+------------------------------+
|
||||
| type | The sequence's type |
|
||||
+------------+------------------------------+
|
||||
|
||||
.. note::
|
||||
This model implements the :ref:`component_sequence_model_sequence-interface`.
|
||||
|
||||
For more detailed information go to `Sylius API Sequence`_.
|
||||
|
||||
.. _Sylius API Sequence: http://api.sylius.org/Sylius/Component/Sequence/Model/Sequence.html
|
||||
|
|
@ -35,7 +35,6 @@ We recommend checking out :doc:`/components/general/index`, which will get you s
|
|||
Registry/index
|
||||
Report/index
|
||||
Resource/index
|
||||
Sequence/index
|
||||
Shipping/index
|
||||
Storage/index
|
||||
Taxation/index
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
* :doc:`/components/Registry/index`
|
||||
* :doc:`/components/Report/index`
|
||||
* :doc:`/components/Resource/index`
|
||||
* :doc:`/components/Sequence/index`
|
||||
* :doc:`/components/Shipping/index`
|
||||
* :doc:`/components/Storage/index`
|
||||
* :doc:`/components/Taxation/index`
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ suites:
|
|||
Report: { namespace: Sylius\Component\Report, psr4_prefix: Sylius\Component\Report, spec_path: src/Sylius/Component/Report, src_path: src/Sylius/Component/Report }
|
||||
Resource: { namespace: Sylius\Component\Resource, psr4_prefix: Sylius\Component\Resource, spec_path: src/Sylius/Component/Resource, src_path: src/Sylius/Component/Resource }
|
||||
Review: { namespace: Sylius\Component\Review, psr4_prefix: Sylius\Component\Review, spec_path: src/Sylius/Component/Review, src_path: src/Sylius/Component/Review }
|
||||
Sequence: { namespace: Sylius\Component\Sequence, psr4_prefix: Sylius\Component\Sequence, spec_path: src/Sylius/Component/Sequence, src_path: src/Sylius/Component/Sequence }
|
||||
Shipping: { namespace: Sylius\Component\Shipping, psr4_prefix: Sylius\Component\Shipping, spec_path: src/Sylius/Component/Shipping, src_path: src/Sylius/Component/Shipping }
|
||||
Storage: { namespace: Sylius\Component\Storage, psr4_prefix: Sylius\Component\Storage, spec_path: src/Sylius/Component/Storage, src_path: src/Sylius/Component/Storage }
|
||||
Taxation: { namespace: Sylius\Component\Taxation, psr4_prefix: Sylius\Component\Taxation, spec_path: src/Sylius/Component/Taxation, src_path: src/Sylius/Component/Taxation }
|
||||
|
|
@ -64,7 +63,6 @@ suites:
|
|||
ResourceBundle: { namespace: Sylius\Bundle\ResourceBundle, psr4_prefix: Sylius\Bundle\ResourceBundle, spec_path: src/Sylius/Bundle/ResourceBundle, src_path: src/Sylius/Bundle/ResourceBundle }
|
||||
ReviewBundle: { namespace: Sylius\Bundle\ReviewBundle, psr4_prefix: Sylius\Bundle\ReviewBundle, spec_path: src/Sylius/Bundle/ReviewBundle, src_path: src/Sylius/Bundle/ReviewBundle }
|
||||
SearchBundle: { namespace: Sylius\Bundle\SearchBundle, psr4_prefix: Sylius\Bundle\SearchBundle, spec_path: src/Sylius/Bundle/SearchBundle, src_path: src/Sylius/Bundle/SearchBundle }
|
||||
SequenceBundle: { namespace: Sylius\Bundle\SequenceBundle, psr4_prefix: Sylius\Bundle\SequenceBundle, spec_path: src/Sylius/Bundle/SequenceBundle, src_path: src/Sylius/Bundle/SequenceBundle }
|
||||
SettingsBundle: { namespace: Sylius\Bundle\SettingsBundle, psr4_prefix: Sylius\Bundle\SettingsBundle, spec_path: src/Sylius/Bundle/SettingsBundle, src_path: src/Sylius/Bundle/SettingsBundle }
|
||||
ShippingBundle: { namespace: Sylius\Bundle\ShippingBundle, psr4_prefix: Sylius\Bundle\ShippingBundle, spec_path: src/Sylius/Bundle/ShippingBundle, src_path: src/Sylius/Bundle/ShippingBundle }
|
||||
ShopBundle: { namespace: Sylius\Bundle\ShopBundle, psr4_prefix: Sylius\Bundle\ShopBundle, spec_path: src/Sylius/Bundle/ShopBundle, src_path: src/Sylius/Bundle/ShopBundle }
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ class Kernel extends HttpKernel
|
|||
new \Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle(),
|
||||
new \Sylius\Bundle\FlowBundle\SyliusFlowBundle(),
|
||||
new \Sylius\Bundle\PricingBundle\SyliusPricingBundle(),
|
||||
new \Sylius\Bundle\SequenceBundle\SyliusSequenceBundle(),
|
||||
new \Sylius\Bundle\ContentBundle\SyliusContentBundle(),
|
||||
new \Sylius\Bundle\RbacBundle\SyliusRbacBundle(),
|
||||
new \Sylius\Bundle\UserBundle\SyliusUserBundle(),
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ class SyliusCoreExtension extends AbstractResourceExtension implements PrependEx
|
|||
'sylius_promotion',
|
||||
'sylius_review',
|
||||
'sylius_report',
|
||||
'sylius_sequence',
|
||||
'sylius_settings',
|
||||
'sylius_shipping',
|
||||
'sylius_mailer',
|
||||
|
|
|
|||
|
|
@ -10,7 +10,3 @@ jms_serializer:
|
|||
sylius-order:
|
||||
namespace_prefix: "Sylius\\Component\\Order"
|
||||
path: "@SyliusOrderBundle/Resources/config/serializer"
|
||||
|
||||
sylius_sequence:
|
||||
generators:
|
||||
"%sylius.model.order.class%": sylius.sequence.sequential_number_generator
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
"sylius/order": "^1.0",
|
||||
"sylius/money-bundle": "^1.0",
|
||||
"sylius/resource-bundle": "^1.0",
|
||||
"sylius/sequence-bundle": "^1.0",
|
||||
"symfony/framework-bundle": "^2.8"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
|
|||
5
src/Sylius/Bundle/SequenceBundle/.gitignore
vendored
5
src/Sylius/Bundle/SequenceBundle/.gitignore
vendored
|
|
@ -1,5 +0,0 @@
|
|||
vendor/
|
||||
bin/
|
||||
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
CHANGELOG
|
||||
=========
|
||||
|
||||
### v0.10.0
|
||||
|
||||
* Initial dev release
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\SequenceBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Registers all generators.
|
||||
*
|
||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||
*/
|
||||
class RegisterGeneratorsPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('sylius.registry.number_generator')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$generators = $container->getParameter('sylius.sequence.generators');
|
||||
$registry = $container->getDefinition('sylius.registry.number_generator');
|
||||
|
||||
foreach ($generators as $interface => $generator) {
|
||||
$registry->addMethodCall('register', [$interface, new Reference($generator)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\SequenceBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Component\Resource\Factory\Factory;
|
||||
use Sylius\Component\Sequence\Model\Sequence;
|
||||
use Sylius\Component\Sequence\Model\SequenceInterface;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* This class contains the configuration information for the bundle.
|
||||
*
|
||||
* This information is solely responsible for how the different configuration
|
||||
* sections are normalized, and merged.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('sylius_sequence');
|
||||
|
||||
$rootNode
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
$this->addResourcesSection($rootNode);
|
||||
$this->addGeneratorsSection($rootNode);
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addResourcesSection(ArrayNodeDefinition $node)
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('resources')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->arrayNode('sequence')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->variableNode('options')->end()
|
||||
->arrayNode('classes')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('model')->defaultValue(Sequence::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('interface')->defaultValue(SequenceInterface::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
|
||||
->scalarNode('repository')->cannotBeEmpty()->end()
|
||||
->scalarNode('factory')->defaultValue(Factory::class)->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addGeneratorsSection(ArrayNodeDefinition $node)
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('generators')
|
||||
->useAttributeAsKey('interface')
|
||||
->prototype('scalar')
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\SequenceBundle\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* Sequence extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SyliusSequenceExtension extends AbstractResourceExtension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$config = $this->processConfiguration($this->getConfiguration($config, $container), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$this->registerResources('sylius', $config['driver'], $config['resources'], $container);
|
||||
|
||||
$configFiles = [
|
||||
'services.xml',
|
||||
sprintf('driver/%s.xml', $config['driver']),
|
||||
];
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setParameter('sylius.sequence.generators', $config['generators']);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,155 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\SequenceBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Event\PreFlushEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
use Sylius\Component\Registry\NonExistingServiceException;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
use Sylius\Component\Sequence\Model\SequenceInterface;
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
use Sylius\Component\Sequence\Registry\NonExistingGeneratorException;
|
||||
use Sylius\Component\Sequence\SyliusSequenceEvents;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
/**
|
||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||
* @author Saša Stamenković <umpirsky@gmail.com>
|
||||
*/
|
||||
class NumberListener
|
||||
{
|
||||
/**
|
||||
* @var ServiceRegistryInterface
|
||||
*/
|
||||
protected $registry;
|
||||
|
||||
/**
|
||||
* @var EventManager
|
||||
*/
|
||||
protected $eventManager;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sequenceClass;
|
||||
|
||||
/**
|
||||
* @var SequenceSubjectInterface[]
|
||||
*/
|
||||
protected $entitiesEnabled = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $sequences = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $listenerEnabled = false;
|
||||
|
||||
/**
|
||||
* @param ServiceRegistryInterface $registry
|
||||
* @param EventManager $eventManager
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param string $sequenceClass
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceRegistryInterface $registry,
|
||||
EventManager $eventManager,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
$sequenceClass
|
||||
) {
|
||||
$this->registry = $registry;
|
||||
$this->eventManager = $eventManager;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->sequenceClass = $sequenceClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function enableEntity(SequenceSubjectInterface $subject)
|
||||
{
|
||||
$this->entitiesEnabled[spl_object_hash($subject)] = $subject;
|
||||
|
||||
if (!$this->listenerEnabled) {
|
||||
$this->eventManager->addEventListener(Events::preFlush, $this);
|
||||
$this->listenerEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preFlush(PreFlushEventArgs $args)
|
||||
{
|
||||
$em = $args->getEntityManager();
|
||||
|
||||
foreach ($this->entitiesEnabled as $entity) {
|
||||
try {
|
||||
$generator = $this->registry->get($entity);
|
||||
} catch (NonExistingServiceException $e) {
|
||||
throw new NonExistingGeneratorException($entity, $e);
|
||||
}
|
||||
|
||||
$sequence = $this->getSequence($entity->getSequenceType(), $em);
|
||||
|
||||
$event = new GenericEvent($entity);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
sprintf(SyliusSequenceEvents::PRE_GENERATE, $entity->getSequenceType()),
|
||||
$event
|
||||
);
|
||||
|
||||
$generator->generate($entity, $sequence);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
sprintf(SyliusSequenceEvents::POST_GENERATE, $entity->getSequenceType()),
|
||||
$event
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*
|
||||
* @return SequenceInterface
|
||||
*/
|
||||
protected function getSequence($type, EntityManagerInterface $entityManager)
|
||||
{
|
||||
if (isset($this->sequences[$type])) {
|
||||
return $this->sequences[$type];
|
||||
}
|
||||
|
||||
$sequence = $entityManager
|
||||
->getRepository($this->sequenceClass)
|
||||
->findOneBy(['type' => $type])
|
||||
;
|
||||
|
||||
if (null === $sequence) {
|
||||
$sequence = new $this->sequenceClass($type);
|
||||
$entityManager->persist($sequence);
|
||||
}
|
||||
|
||||
return $this->sequences[$type] = $sequence;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
SyliusSequenceBundle [](http://travis-ci.org/Sylius/SyliusSequenceBundle)
|
||||
====================
|
||||
|
||||
Sequence system with web editing interface for [**Symfony2**](http://symfony.com) applications.
|
||||
|
||||
Sylius
|
||||
------
|
||||
|
||||
**Sylius** - Modern ecommerce for Symfony2. Visit [Sylius.org](http://sylius.org).
|
||||
|
||||
[phpspec](http://phpspec.net) examples
|
||||
--------------------------------------
|
||||
|
||||
```bash
|
||||
$ composer install
|
||||
$ bin/phpspec run -f pretty
|
||||
```
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Documentation is available on [**docs.sylius.org**](http://docs.sylius.org/en/latest/bundles/SyliusSequenceBundle/index.html).
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
All informations about contributing to Sylius can be found on [this page](http://docs.sylius.org/en/latest/contributing/index.html).
|
||||
|
||||
Mailing lists
|
||||
-------------
|
||||
|
||||
### Users
|
||||
|
||||
Questions? Feel free to ask on [users mailing list](http://groups.google.com/group/sylius).
|
||||
|
||||
### Developers
|
||||
|
||||
To contribute and develop this bundle, use the [developers mailing list](http://groups.google.com/group/sylius-dev).
|
||||
|
||||
Sylius twitter account
|
||||
----------------------
|
||||
|
||||
If you want to keep up with updates, [follow the official Sylius account on twitter](http://twitter.com/Sylius).
|
||||
|
||||
Bug tracking
|
||||
------------
|
||||
|
||||
This bundle uses [GitHub issues](https://github.com/Sylius/Sylius/issues).
|
||||
If you have found bug, please create an issue.
|
||||
|
||||
Versioning
|
||||
----------
|
||||
|
||||
Releases will be numbered with the format `major.minor.patch`.
|
||||
|
||||
And constructed with the following guidelines.
|
||||
|
||||
* Breaking backwards compatibility bumps the major.
|
||||
* New additions without breaking backwards compatibility bumps the minor.
|
||||
* Bug fixes and misc changes bump the patch.
|
||||
|
||||
For more information on SemVer, please visit [semver.org website](http://semver.org/).
|
||||
This versioning method is same for all **Sylius** bundles and applications.
|
||||
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
License can be found [here](https://github.com/Sylius/SyliusSequenceBundle/blob/master/Resources/meta/LICENSE).
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
The bundle was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
|
||||
See the list of [contributors](https://github.com/Sylius/SyliusSequenceBundle/contributors).
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
|
||||
This file is part of the Sylius package.
|
||||
|
||||
(c) Paweł Jędrzejewski
|
||||
|
||||
For the full copyright and license information, please view the LICENSE
|
||||
file that was distributed with this source code.
|
||||
|
||||
-->
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<mapped-superclass name="Sylius\Component\Sequence\Model\Sequence" table="sylius_sequence">
|
||||
<id name="id" column="id" type="integer">
|
||||
<generator strategy="AUTO" />
|
||||
</id>
|
||||
<field name="index" column="idx" type="integer" />
|
||||
<field name="type" type="string" unique="true" />
|
||||
</mapped-superclass>
|
||||
|
||||
</doctrine-mapping>
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!--
|
||||
|
||||
This file is part of the Sylius package.
|
||||
|
||||
(c) Paweł Jędrzejewski
|
||||
|
||||
For the full copyright and license information, please view the LICENSE
|
||||
file that was distributed with this source code.
|
||||
|
||||
-->
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||
http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="sylius.sequence.doctrine_number_listener.class">Sylius\Bundle\SequenceBundle\Doctrine\ORM\NumberListener</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="sylius.sequence.doctrine_number_listener" class="%sylius.sequence.doctrine_number_listener.class%">
|
||||
<argument type="service" id="sylius.registry.number_generator" />
|
||||
<argument type="service">
|
||||
<service class="Doctrine\Common\EventManager" factory-service="doctrine.orm.entity_manager" factory-method="getEventManager" />
|
||||
</argument>
|
||||
<argument type="service" id="event_dispatcher" />
|
||||
<argument>%sylius.model.sequence.class%</argument>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
</container>
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||
http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="sylius.registry.number_generator.class">Sylius\Component\Sequence\Registry\GeneratorRegistry</parameter>
|
||||
|
||||
<parameter key="sylius.sequence.number_generator.interface">Sylius\Component\Sequence\Number\GeneratorInterface</parameter>
|
||||
|
||||
<parameter key="sylius.sequence.sequential_number_generator.class">Sylius\Component\Sequence\Number\SequentialGenerator</parameter>
|
||||
<parameter key="sylius.sequence.hash_number_generator.class">Sylius\Component\Sequence\Number\HashGenerator</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="sylius.registry.number_generator" class="%sylius.registry.number_generator.class%">
|
||||
<argument>%sylius.sequence.number_generator.interface%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.sequence.sequential_number_generator" class="%sylius.sequence.sequential_number_generator.class%" />
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2011-2016 Paweł Jędrzejewski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\SequenceBundle;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
|
||||
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
|
||||
use Sylius\Bundle\SequenceBundle\DependencyInjection\Compiler\RegisterGeneratorsPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Sequence system for ecommerce Symfony2 applications.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SyliusSequenceBundle extends AbstractResourceBundle
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSupportedDrivers()
|
||||
{
|
||||
return [
|
||||
SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
parent::build($container);
|
||||
|
||||
$container->addCompilerPass(new RegisterGeneratorsPass());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getModelNamespace()
|
||||
{
|
||||
return 'Sylius\Component\Sequence\Model';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
{
|
||||
"name": "sylius/sequence-bundle",
|
||||
"type": "symfony-bundle",
|
||||
"description": "Sequence system for Symfony2 applications.",
|
||||
"keywords": ["config", "configuration", "sequence", "shop", "webshop", "ecommerce"],
|
||||
"homepage": "http://sylius.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paweł Jędrzejewski",
|
||||
"homepage": "http://pjedrzejewski.com"
|
||||
},
|
||||
{
|
||||
"name": "Alexandre Bacco",
|
||||
"homepage": "http://alex.bacco.fr"
|
||||
},
|
||||
{
|
||||
"name": "Sylius project",
|
||||
"homepage": "http://sylius.org"
|
||||
},
|
||||
{
|
||||
"name": "Community contributions",
|
||||
"homepage": "http://github.com/Sylius/Sylius/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.6|^7.0",
|
||||
|
||||
"sylius/resource-bundle": "^1.0",
|
||||
"sylius/sequence": "^1.0",
|
||||
"symfony/framework-bundle": "^2.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^2.4",
|
||||
"doctrine/orm": "^2.4.8,<2.5"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Sylius\\Bundle\\SequenceBundle\\": "" }
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": { "spec\\Sylius\\Bundle\\SequenceBundle\\": "spec/" }
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../../*/*"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
suites:
|
||||
main:
|
||||
namespace: Sylius\Bundle\SequenceBundle
|
||||
psr4_prefix: Sylius\Bundle\SequenceBundle
|
||||
src_path: .
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Bundle\SequenceBundle\DependencyInjection\Compiler;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <arn0d.dev@gmail.com>
|
||||
*/
|
||||
class RegisterGeneratorsPassSpec extends ObjectBehavior
|
||||
{
|
||||
public function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\SequenceBundle\DependencyInjection\Compiler\RegisterGeneratorsPass');
|
||||
}
|
||||
|
||||
public function it_is_a_compiler_pass()
|
||||
{
|
||||
$this->shouldImplement(CompilerPassInterface::class);
|
||||
}
|
||||
|
||||
public function it_processes_the_calculators_services(ContainerBuilder $container, Definition $registry)
|
||||
{
|
||||
$container->hasDefinition('sylius.registry.number_generator')->shouldBeCalled()->willReturn(true);
|
||||
$container->getDefinition('sylius.registry.number_generator')->shouldBeCalled()->willReturn($registry);
|
||||
|
||||
$container->getParameter('sylius.sequence.generators')->shouldBeCalled()->willReturn(['generator']);
|
||||
|
||||
$registry->addMethodCall('register', Argument::type('array'))->shouldBeCalled();
|
||||
|
||||
$this->process($container);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Bundle\SequenceBundle\Doctrine\ORM;
|
||||
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Event\PreFlushEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
use Sylius\Component\Sequence\Model\Sequence;
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
use Sylius\Component\Sequence\Number\GeneratorInterface;
|
||||
use Sylius\Component\Sequence\SyliusSequenceEvents;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
/**
|
||||
* @author Arnaud Langlade <arn0d.dev@gmail.com>
|
||||
*/
|
||||
class NumberListenerSpec extends ObjectBehavior
|
||||
{
|
||||
function let(
|
||||
ServiceRegistryInterface $registry,
|
||||
EventManager $eventManager,
|
||||
EventDispatcherInterface $eventDispatcher
|
||||
) {
|
||||
$this->beConstructedWith(
|
||||
$registry,
|
||||
$eventManager,
|
||||
$eventDispatcher,
|
||||
Sequence::class
|
||||
);
|
||||
}
|
||||
|
||||
function it_enable_listener_on_specific_entity(SequenceSubjectInterface $subject, $eventManager)
|
||||
{
|
||||
$eventManager->addEventListener(
|
||||
Events::preFlush,
|
||||
Argument::type('Sylius\Bundle\SequenceBundle\Doctrine\ORM\NumberListener')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->enableEntity($subject);
|
||||
}
|
||||
|
||||
function it_applies_generator(
|
||||
PreFlushEventArgs $args,
|
||||
EntityManager $entityManager,
|
||||
SequenceSubjectInterface $entity,
|
||||
GeneratorInterface $generator,
|
||||
EntityRepository $sequenceRepository,
|
||||
Sequence $sequence,
|
||||
$registry,
|
||||
$eventDispatcher
|
||||
) {
|
||||
$this->enableEntity($entity);
|
||||
|
||||
$args->getEntityManager()->willReturn($entityManager);
|
||||
|
||||
$registry->get($entity)
|
||||
->willReturn($generator);
|
||||
|
||||
$entity->getSequenceType()->willReturn('sequence_type');
|
||||
|
||||
$entityManager->getRepository(Sequence::class)->willReturn($sequenceRepository);
|
||||
$sequenceRepository->findOneBy(['type' => 'sequence_type'])->willReturn($sequence);
|
||||
|
||||
$eventDispatcher->dispatch(
|
||||
sprintf(SyliusSequenceEvents::PRE_GENERATE, 'sequence_type'),
|
||||
Argument::type('Symfony\Component\EventDispatcher\GenericEvent')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$generator->generate($entity, $sequence)->shouldBeCalled();
|
||||
|
||||
$eventDispatcher->dispatch(
|
||||
sprintf(SyliusSequenceEvents::POST_GENERATE, 'sequence_type'),
|
||||
Argument::type('Symfony\Component\EventDispatcher\GenericEvent')
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->preFlush($args);
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,6 @@
|
|||
"sylius/rbac": "^1.0",
|
||||
"sylius/registry": "^1.0",
|
||||
"sylius/resource": "^1.0",
|
||||
"sylius/sequence": "^1.0",
|
||||
"sylius/shipping": "^1.0",
|
||||
"sylius/storage": "^1.0",
|
||||
"sylius/taxation": "^1.0",
|
||||
|
|
|
|||
|
|
@ -166,14 +166,6 @@ class Order implements OrderInterface
|
|||
$this->notes = $notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSequenceType()
|
||||
{
|
||||
return 'order';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ namespace Sylius\Component\Order\Model;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Sylius\Component\Resource\Model\ResourceInterface;
|
||||
use Sylius\Component\Resource\Model\TimestampableInterface;
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
|
|
@ -23,7 +22,6 @@ interface OrderInterface extends
|
|||
AdjustableInterface,
|
||||
CommentAwareInterface,
|
||||
ResourceInterface,
|
||||
SequenceSubjectInterface,
|
||||
TimestampableInterface
|
||||
{
|
||||
const STATE_NEW = 'new';
|
||||
|
|
|
|||
|
|
@ -13,12 +13,11 @@ namespace Sylius\Component\Order\Repository;
|
|||
|
||||
use Sylius\Component\Order\Model\OrderInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Sylius\Component\Sequence\Repository\HashSubjectRepositoryInterface;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface OrderRepositoryInterface extends RepositoryInterface, HashSubjectRepositoryInterface
|
||||
interface OrderRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return int
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.6|^7.0",
|
||||
|
||||
"sylius/sequence": "^1.0"
|
||||
"php": "^5.6|^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^2.4"
|
||||
|
|
|
|||
5
src/Sylius/Component/Sequence/.gitignore
vendored
5
src/Sylius/Component/Sequence/.gitignore
vendored
|
|
@ -1,5 +0,0 @@
|
|||
vendor/
|
||||
bin/
|
||||
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
CHANGELOG
|
||||
=========
|
||||
|
||||
### v0.10.0
|
||||
|
||||
* Initial dev release.
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2011-2016 Paweł Jędrzejewski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Model;
|
||||
|
||||
class Sequence implements SequenceInterface
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $index = 0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIndex()
|
||||
{
|
||||
return $this->index;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function incrementIndex()
|
||||
{
|
||||
++$this->index;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Model;
|
||||
|
||||
use Sylius\Component\Resource\Model\ResourceInterface;
|
||||
|
||||
interface SequenceInterface extends ResourceInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getIndex();
|
||||
|
||||
/**
|
||||
* Increment sequence type
|
||||
*/
|
||||
public function incrementIndex();
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Model;
|
||||
|
||||
/**
|
||||
* Interface for Sequence subjects, like Order, Invoice, etc.
|
||||
*
|
||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||
*/
|
||||
interface SequenceSubjectInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSequenceType();
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNumber();
|
||||
|
||||
/**
|
||||
* @param string
|
||||
*/
|
||||
public function setNumber($number);
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Number;
|
||||
|
||||
use Sylius\Component\Sequence\Model\SequenceInterface;
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
|
||||
/**
|
||||
* Default order number generator.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Saša Stamenković <umpirsky@gmail.com>
|
||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||
*/
|
||||
abstract class AbstractGenerator implements GeneratorInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate(SequenceSubjectInterface $subject, SequenceInterface $sequence)
|
||||
{
|
||||
if (null !== $subject->getNumber()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subject->setNumber($this->generateNumber($sequence->getIndex(), $subject));
|
||||
|
||||
$sequence->incrementIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the number
|
||||
*
|
||||
* @param int $index
|
||||
* @param SequenceSubjectInterface $subject
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function generateNumber($index, SequenceSubjectInterface $subject);
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Number;
|
||||
|
||||
use Sylius\Component\Sequence\Model\SequenceInterface;
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
|
||||
/**
|
||||
* Number generator interface.
|
||||
* The implementation should generate next order number.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface GeneratorInterface
|
||||
{
|
||||
/**
|
||||
* Generate and apply next available number for given subject.
|
||||
*
|
||||
* @param SequenceSubjectInterface $subject
|
||||
* @param SequenceInterface $sequence
|
||||
*/
|
||||
public function generate(SequenceSubjectInterface $subject, SequenceInterface $sequence);
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Number;
|
||||
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
use Sylius\Component\Sequence\Repository\HashSubjectRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Hash order number generator.
|
||||
*
|
||||
* @author Myke Hines <myke@webhines.com>
|
||||
*/
|
||||
class HashGenerator extends AbstractGenerator implements GeneratorInterface
|
||||
{
|
||||
/**
|
||||
* @var HashSubjectRepositoryInterface
|
||||
*/
|
||||
protected $subjectRepository;
|
||||
|
||||
public function __construct(HashSubjectRepositoryInterface $subjectRepository)
|
||||
{
|
||||
$this->subjectRepository = $subjectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* This generates a 3 by 7 by 7 digit number (much like amazon's order identifier)
|
||||
* e.g. 105-3958356-3707476
|
||||
*/
|
||||
protected function generateNumber($index, SequenceSubjectInterface $order)
|
||||
{
|
||||
do {
|
||||
$number = $this->generateSegment(3).'-'.$this->generateSegment(7).'-'.$this->generateSegment(7);
|
||||
} while ($this->subjectRepository->isNumberUsed($number));
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a randomized segment
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return string Random characters
|
||||
*/
|
||||
protected function generateSegment($length)
|
||||
{
|
||||
return substr(str_pad(mt_rand(), $length, 0, STR_PAD_LEFT), 0, $length);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Number;
|
||||
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
|
||||
/**
|
||||
* Default order number generator.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Saša Stamenković <umpirsky@gmail.com>
|
||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||
*/
|
||||
class SequentialGenerator extends AbstractGenerator implements GeneratorInterface
|
||||
{
|
||||
/**
|
||||
* Order number max length.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numberLength;
|
||||
|
||||
/**
|
||||
* Start number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $startNumber;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $numberLength
|
||||
* @param int $startNumber
|
||||
*/
|
||||
public function __construct($numberLength = 9, $startNumber = 1)
|
||||
{
|
||||
$this->numberLength = $numberLength;
|
||||
$this->startNumber = $startNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateNumber($index, SequenceSubjectInterface $subject)
|
||||
{
|
||||
$number = $this->startNumber + $index;
|
||||
|
||||
return str_pad($number, $this->numberLength, 0, STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
Sequence Component [](http://travis-ci.org/Sylius/Sequence)
|
||||
===================
|
||||
|
||||
Sequences engine for PHP objects.
|
||||
|
||||
Sylius
|
||||
------
|
||||
|
||||
Modern ecommerce for PHP and Symfony2. Visit [Sylius.org](http://sylius.org).
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Documentation is available on [**docs.sylius.org**](http://docs.sylius.org/en/latest/components/Sequence/index.html).
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
All instructions for contributing to Sylius can be found in the [Contributing Guide](http://docs.sylius.org/en/latest/contributing/index.html).
|
||||
|
||||
Support
|
||||
-------
|
||||
|
||||
If you have a question regarding the usage of this library, please ask on
|
||||
[Stackoverflow](http://stackoverflow.com). You should use "sylius"
|
||||
tag when posting and make sure to [browse existing questions](http://http://stackoverflow.com/questions/tagged/sylius).
|
||||
|
||||
Sylius on Twitter
|
||||
-----------------
|
||||
|
||||
[Follow the official Sylius account on Twitter!](http://twitter.com/Sylius).
|
||||
|
||||
Bug Tracking
|
||||
------------
|
||||
|
||||
If you find a bug, please refer to the [Reporting a Bug](http://docs.sylius.org/en/latest/contributing/code/bugs.html) guide.
|
||||
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
License can be found [here](https://github.com/Sylius/Sequence/blob/master/LICENSE).
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
The component was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
|
||||
See the list of [contributors](https://github.com/Sylius/Sequence/contributors).
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Registry;
|
||||
|
||||
use Sylius\Component\Registry\NonExistingServiceException;
|
||||
use Sylius\Component\Registry\ServiceRegistry;
|
||||
use Sylius\Component\Sequence\Number\GeneratorInterface;
|
||||
|
||||
/**
|
||||
* Registry for generators
|
||||
*
|
||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||
*/
|
||||
class GeneratorRegistry extends ServiceRegistry
|
||||
{
|
||||
/**
|
||||
* Return the generator used for the given entity
|
||||
*
|
||||
* @param object $entity
|
||||
*
|
||||
* @return GeneratorInterface
|
||||
*
|
||||
* @throws NonExistingServiceException
|
||||
*/
|
||||
public function get($entity)
|
||||
{
|
||||
foreach ($this->services as $interface => $generator) {
|
||||
if ($entity instanceof $interface) {
|
||||
return $generator;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NonExistingServiceException(get_class($entity));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Registry;
|
||||
|
||||
use Sylius\Component\Registry\NonExistingServiceException;
|
||||
|
||||
/**
|
||||
* @author Saša Stamenković <umpirsky@gmail.com>
|
||||
*/
|
||||
class NonExistingGeneratorException extends \InvalidArgumentException
|
||||
{
|
||||
public function __construct($entity, NonExistingServiceException $e)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf(
|
||||
'Generator for entity "%s" does not exist. Please consider adding it to your configuration like this: sylius_sequence.generators: %%sylius.model.class%%: sylius.sequence.sequential_number_generator',
|
||||
get_class($entity)
|
||||
),
|
||||
$e->getCode(),
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence\Repository;
|
||||
|
||||
/**
|
||||
* Repository interface for model which needs number uniqueness check before applying (like random numbers)
|
||||
*
|
||||
* @author Alexandre Bacco <alexandre.bacco@gmail.com>
|
||||
*/
|
||||
interface HashSubjectRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Is the given number used?
|
||||
*
|
||||
* @param $number string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNumberUsed($number);
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Component\Sequence;
|
||||
|
||||
class SyliusSequenceEvents
|
||||
{
|
||||
const PRE_GENERATE = 'sylius.sequence.%s.pre_generate';
|
||||
const POST_GENERATE = 'sylius.sequence.%s.post_generate';
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
{
|
||||
"name": "sylius/sequence",
|
||||
"type": "library",
|
||||
"description": "Component for handling sequences in PHP projects.",
|
||||
"keywords": ["shop", "ecommerce", "sequence", "feature"],
|
||||
"homepage": "http://sylius.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paweł Jędrzejewski",
|
||||
"homepage": "http://pjedrzejewski.com"
|
||||
},
|
||||
{
|
||||
"name": "Alexandre Bacco",
|
||||
"homepage": "http://alex.bacco.fr"
|
||||
},
|
||||
{
|
||||
"name": "Sylius project",
|
||||
"homepage": "http://sylius.org"
|
||||
},
|
||||
{
|
||||
"name": "Community contributions",
|
||||
"homepage": "http://github.com/Sylius/Sylius/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.6|^7.0",
|
||||
|
||||
"sylius/registry": "^1.0",
|
||||
"sylius/resource": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^2.4"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Sylius\\Component\\Sequence\\": "" }
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../../*/*"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
suites:
|
||||
main:
|
||||
namespace: Sylius\Component\Sequence
|
||||
psr4_prefix: Sylius\Component\Sequence
|
||||
src_path: .
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace spec\Sylius\Component\Sequence\Number;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Component\Sequence\Model\SequenceInterface;
|
||||
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
class SequentialGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Sequence\Number\SequentialGenerator');
|
||||
}
|
||||
|
||||
function it_generates_000001_number_for_first_subject(
|
||||
SequenceSubjectInterface $subject,
|
||||
SequenceInterface $sequence
|
||||
) {
|
||||
$subject->getNumber()->willReturn(null);
|
||||
$subject->getSequenceType()->willReturn('order');
|
||||
|
||||
$sequence->getIndex()->willReturn(0);
|
||||
$sequence->incrementIndex()->shouldBeCalled();
|
||||
|
||||
$subject->setNumber('000000001')->shouldBeCalled();
|
||||
|
||||
$this->generate($subject, $sequence);
|
||||
}
|
||||
|
||||
function it_generates_a_correct_number_for_following_subjects(
|
||||
SequenceSubjectInterface $subject,
|
||||
SequenceInterface $sequence
|
||||
) {
|
||||
$subject->getNumber()->willReturn(null);
|
||||
$subject->getSequenceType()->willReturn('order');
|
||||
|
||||
$sequence->getIndex()->willReturn(222);
|
||||
$sequence->incrementIndex()->shouldBeCalled();
|
||||
|
||||
$subject->setNumber('000000223')->shouldBeCalled();
|
||||
|
||||
$this->generate($subject, $sequence);
|
||||
}
|
||||
|
||||
function it_starts_at_start_number_if_specified(SequenceSubjectInterface $subject, SequenceInterface $sequence)
|
||||
{
|
||||
$this->beConstructedWith(6, 123);
|
||||
|
||||
$subject->getNumber()->willReturn(null);
|
||||
$subject->getSequenceType()->willReturn('order');
|
||||
|
||||
$sequence->getIndex()->willReturn(0);
|
||||
$sequence->incrementIndex()->shouldBeCalled();
|
||||
|
||||
$subject->setNumber('000123')->shouldBeCalled();
|
||||
|
||||
$this->generate($subject, $sequence);
|
||||
}
|
||||
|
||||
function it_leaves_existing_numbers_alone(SequenceSubjectInterface $subject, SequenceInterface $sequence)
|
||||
{
|
||||
$subject->getNumber()->willReturn('123');
|
||||
$subject->setNumber(Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$sequence->incrementIndex()->shouldNotBeCalled();
|
||||
|
||||
$this->generate($subject, $sequence);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue