mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Remove Storage component
This commit is contained in:
parent
9c4cb44897
commit
c171c7743a
33 changed files with 55 additions and 860 deletions
|
|
@ -141,7 +141,6 @@
|
|||
"sylius/settings-bundle": "self.version",
|
||||
"sylius/shipping": "self.version",
|
||||
"sylius/shipping-bundle": "self.version",
|
||||
"sylius/storage": "self.version",
|
||||
"sylius/taxation": "self.version",
|
||||
"sylius/taxation-bundle": "self.version",
|
||||
"sylius/taxonomy": "self.version",
|
||||
|
|
|
|||
8
composer.lock
generated
8
composer.lock
generated
|
|
@ -4,8 +4,8 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "096ea8f8521cb8a5894d21d914aa31e7",
|
||||
"content-hash": "10d47d5d2cdc51a4db57c6dc19aada13",
|
||||
"hash": "ae6c239b6ea45b3b7bf05be52d9fe3f9",
|
||||
"content-hash": "3ad3b198a80706399d89c8efc51a017d",
|
||||
"packages": [
|
||||
{
|
||||
"name": "behat/transliterator",
|
||||
|
|
@ -8443,7 +8443,7 @@
|
|||
"email": "adrien.brault@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "William Durand",
|
||||
"name": "William DURAND",
|
||||
"email": "william.durand1@gmail.com"
|
||||
}
|
||||
],
|
||||
|
|
@ -8536,7 +8536,7 @@
|
|||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "William DURAND",
|
||||
"name": "William Durand",
|
||||
"email": "william.durand1@gmail.com",
|
||||
"homepage": "http://www.willdurand.fr"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,44 +28,7 @@ convert currency's code into a human friendly form.
|
|||
CurrencyContext
|
||||
---------------
|
||||
|
||||
The **CurrencyContext** is responsible for keeping the currently
|
||||
set and default currency names in a given :doc:`/components/Storage/index`.
|
||||
|
||||
.. tip::
|
||||
You can use a custom storage, as long as it implements the :ref:`component_storage_storage-interface`.
|
||||
|
||||
In this example let's use the default :ref:`component_storage_session-storage`.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Sylius\Component\Currency\Context\CurrencyContext;
|
||||
use Sylius\Component\Storage\SessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
$session = new Session();
|
||||
$session->start();
|
||||
$sessionStorage = new SessionStorage($session);
|
||||
|
||||
$currencyCode = 'USD'; // The currency code which will be used by default in this context.
|
||||
|
||||
$currencyContext = new CurrencyContext($sessionStorage, $currencyCode);
|
||||
|
||||
$currencyContext->getDefaultCurrencyCode(); // Returns 'USD'.
|
||||
$currencyContext->getCurrencyCode('GBP'); // Returns 'USD' as the given code is not in storage.
|
||||
$currencyContext->setCurrencyCode('GBP');
|
||||
$currencyContext->getCurrencyCode('GBP'); // Returns 'GBP' for now it's available in the storage.
|
||||
|
||||
Be aware that setting the default currency is done only once while creating the context,
|
||||
afterwards you cannot change it.
|
||||
|
||||
.. note::
|
||||
This service implements the :ref:`component_currency_context_currency-context-interface`.
|
||||
|
||||
For more detailed information go to `Sylius API CurrencyContext`_.
|
||||
|
||||
.. _Sylius API CurrencyContext: http://api.sylius.org/Sylius/Component/Currency/Context/CurrencyContext.html
|
||||
...
|
||||
|
||||
.. _component_currency_converter_currency-converter:
|
||||
|
||||
|
|
|
|||
|
|
@ -4,68 +4,7 @@ Basic Usage
|
|||
LocaleContext
|
||||
-------------
|
||||
|
||||
The **LocaleContext** allows you to manage the currently used locale.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Sylius\Component\Storage\StorageInterface;
|
||||
|
||||
class Storage implements StorageInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData($key)
|
||||
{
|
||||
// TODO: Implement hasData() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData($key, $default = null)
|
||||
{
|
||||
// TODO: Implement getData() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setData($key, $value)
|
||||
{
|
||||
// TODO: Implement setData() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeData($key)
|
||||
{
|
||||
// TODO: Implement removeData() method.
|
||||
}
|
||||
}
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Sylius\Component\Locale\Context\LocaleContext;
|
||||
use Sylius\Component\Resource\Repository\InMemoryRepository;
|
||||
|
||||
$storage = new Storage();
|
||||
|
||||
$localeContext = new LocaleContext($storage, 'en_US');
|
||||
|
||||
$localeContext->getDefaultLocale() // Output will be 'en'.
|
||||
$localeContext->getCurrentLocale() // Output based on your storage implementation.
|
||||
$localeContext->setCurrentLocale('us') // It will set your default locale in your storage.
|
||||
|
||||
.. note::
|
||||
For more detailed information go to `Sylius API LocaleContext`_.
|
||||
|
||||
.. _Sylius API LocaleContext: http://api.sylius.org/Sylius/Component/Locale/Context/LocaleContext.html
|
||||
...
|
||||
|
||||
LocaleProvider
|
||||
--------------
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
Basic Usage
|
||||
===========
|
||||
|
||||
Storages are services managing data in any type of container.
|
||||
|
||||
By default there are three storages available:
|
||||
|
||||
* :ref:`component_storage_cookie-storage`
|
||||
* :ref:`component_storage_doctrine-cache-storage`
|
||||
* :ref:`component_storage_session-storage`
|
||||
|
||||
.. tip::
|
||||
Feel free to implement your own storage, using any container you would like!
|
||||
|
||||
Using Storages
|
||||
--------------
|
||||
|
||||
The methods of every **storage** work the same way. The only difference is the type of container we store in.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use // Any service which implements the StorageInterface.
|
||||
|
||||
$storage = // Your storage service.
|
||||
|
||||
$key = 'aeiouy';
|
||||
$value = 'Hello!';
|
||||
|
||||
$storage->setData($key, $value); // Insert your data to the storage.
|
||||
|
||||
$storage->hasData($key); // Returns true as the key is in the storage.
|
||||
$storage->getData($key); // Returns 'Hello'.
|
||||
|
||||
$storage->removeData($key); // Remove your data from the storage.
|
||||
|
||||
$storage->hasData($key) // Now returns false as we removed the key
|
||||
// from the storage along with it's value.
|
||||
|
||||
If the key which you try to get doesn't exist in the storage,
|
||||
the ``getData`` method returns it's second parameter.
|
||||
If it isn't specified, returns null.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
$storage->getData('failure', 'Goodbye'); // Returns 'Goodbye'.
|
||||
$storage->getData('failure'); // Returns null.
|
||||
|
||||
.. _component_storage_cookie-storage:
|
||||
|
||||
Cookie Storage
|
||||
--------------
|
||||
|
||||
**CookieStorage** is used to manage data in the cookies'
|
||||
`ParameterBag`_ of Symfony's `Request`_ class, which needs
|
||||
to be set in the storage before making any operations on it.
|
||||
|
||||
.. _ParameterBag: http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/ParameterBag.html
|
||||
.. _Request: http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Sylius\Component\Storage\CookieStorage;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
$request = // The request which cookies' data you would like to manage.
|
||||
|
||||
$storage = new CookieStorage();
|
||||
|
||||
$storage->setRequest($request);
|
||||
|
||||
.. note::
|
||||
This service implements :ref:`component_storage_storage-interface`.
|
||||
|
||||
.. _component_storage_doctrine-cache-storage:
|
||||
|
||||
Doctrine Cache Storage
|
||||
----------------------
|
||||
|
||||
**DoctrineCacheStorage** is used to manage data in
|
||||
objects implementing the Doctrine's `Cache`_ interface.
|
||||
|
||||
.. _Cache: http://www.doctrine-project.org/api/common/2.5/class-Doctrine.Common.Cache.Cache.html
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Sylius\Component\Storage\DoctrineCacheStorage;
|
||||
|
||||
$cache = // Your doctrine's cache.
|
||||
|
||||
$storage = new DoctrineCacheStorage($cache);
|
||||
|
||||
.. note::
|
||||
This service implements :ref:`component_storage_storage-interface`.
|
||||
|
||||
.. _component_storage_session-storage:
|
||||
|
||||
Session Storage
|
||||
---------------
|
||||
|
||||
**SessionStorage** is used to manage data in any class implementing the Symfony's `SessionInterface`_.
|
||||
|
||||
.. _SessionInterface: http://l3.shihan.me/api/class-Symfony.Component.HttpFoundation.Session.SessionInterface.html
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
use Sylius\Component\Storage\SessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
|
||||
$session = new Session();
|
||||
$session->start();
|
||||
|
||||
$storage = new SessionStorage($session);
|
||||
|
||||
.. note::
|
||||
This service implements :ref:`component_storage_storage-interface`.
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
Storage
|
||||
=======
|
||||
|
||||
Various data storage implementation in PHP.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
installation
|
||||
basic_usage
|
||||
interfaces
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
Installation
|
||||
============
|
||||
|
||||
You can install the component in 2 different ways:
|
||||
|
||||
* :doc:`Install it via Composer </components/general/using_components>` (``sylius/storage`` on `Packagist`_);
|
||||
* Use the official Git repository (https://github.com/Sylius/Storage).
|
||||
|
||||
.. include:: /components/require_autoload.rst.inc
|
||||
|
||||
.. _Packagist: https://packagist.org/packages/sylius/storage
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
Interfaces
|
||||
==========
|
||||
|
||||
.. _component_storage_storage-interface:
|
||||
|
||||
StorageInterface
|
||||
----------------
|
||||
|
||||
The storage interface consists of four methods which need to be implemented in a custom storage
|
||||
and already are in the default ones.
|
||||
|
||||
Methods include all basic operations you could use on a container, so you can either **add**, **retrieve**,
|
||||
**remove** or **check** if the container has specific data.
|
||||
|
||||
.. tip::
|
||||
Any custom storage needs to implement this interface.
|
||||
|
||||
.. note::
|
||||
For more detailed information go to `Sylius API StorageInterface`_.
|
||||
|
||||
.. _Sylius API StorageInterface: http://api.sylius.org/Sylius/Component/Storage/StorageInterface.html
|
||||
|
|
@ -30,7 +30,6 @@ We recommend checking out :doc:`/components/general/index`, which will get you s
|
|||
Registry/index
|
||||
Resource/index
|
||||
Shipping/index
|
||||
Storage/index
|
||||
Taxation/index
|
||||
Taxonomy/index
|
||||
User/index
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
* :doc:`/components/Registry/index`
|
||||
* :doc:`/components/Resource/index`
|
||||
* :doc:`/components/Shipping/index`
|
||||
* :doc:`/components/Storage/index`
|
||||
* :doc:`/components/Taxation/index`
|
||||
* :doc:`/components/Taxonomy/index`
|
||||
* :doc:`/components/User/index`
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ suites:
|
|||
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 }
|
||||
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 }
|
||||
Taxonomy: { namespace: Sylius\Component\Taxonomy, psr4_prefix: Sylius\Component\Taxonomy, spec_path: src/Sylius/Component/Taxonomy, src_path: src/Sylius/Component/Taxonomy }
|
||||
User: { namespace: Sylius\Component\User, psr4_prefix: Sylius\Component\User, spec_path: src/Sylius/Component/User, src_path: src/Sylius/Component/User }
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@
|
|||
<argument type="service" id="sylius.context.channel" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.storage.currency" class="Sylius\Component\Core\Currency\CurrencyStorage">
|
||||
<argument type="service" id="sylius.storage.session" />
|
||||
<service id="sylius.storage.currency" class="Sylius\Component\Core\Currency\SessionBasedCurrencyStorage">
|
||||
<argument type="service" id="session" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.context.currency.core" class="Sylius\Component\Currency\Context\CompositeCurrencyContext" decorates="sylius.context.currency">
|
||||
|
|
@ -78,8 +78,8 @@
|
|||
<argument>%locale%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.storage.locale" class="Sylius\Component\Core\Locale\LocaleStorage">
|
||||
<argument type="service" id="sylius.storage.session" />
|
||||
<service id="sylius.storage.locale" class="Sylius\Component\Core\Locale\SessionBasedLocaleStorage">
|
||||
<argument type="service" id="session" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.context.locale.core" class="Sylius\Component\Locale\Context\CompositeLocaleContext" decorates="sylius.context.locale">
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
<import resource="services/console.xml" />
|
||||
<import resource="services/controller.xml" />
|
||||
<import resource="services/routing.xml" />
|
||||
<import resource="services/storage.xml" />
|
||||
</imports>
|
||||
|
||||
<parameters>
|
||||
|
|
|
|||
|
|
@ -1,26 +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">
|
||||
<services>
|
||||
<service id="sylius.storage.cookie" class="Sylius\Component\Storage\CookieStorage" public="false">
|
||||
<call method="setRequest">
|
||||
<argument type="service" id="request" on-invalid="null" strict="false" />
|
||||
</call>
|
||||
</service>
|
||||
|
||||
<service id="sylius.storage.session" class="Sylius\Component\Storage\SessionStorage" public="false">
|
||||
<argument type="service" id="session" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -27,7 +27,6 @@
|
|||
"friendsofsymfony/rest-bundle": "~1.5",
|
||||
"jms/serializer-bundle": "^0.13|^1.0",
|
||||
"sylius/resource": "^1.0",
|
||||
"sylius/storage": "^1.0",
|
||||
"symfony/expression-language": "^2.8",
|
||||
"symfony/form": "^2.8",
|
||||
"symfony/validator": "^2.8",
|
||||
|
|
|
|||
|
|
@ -13,24 +13,24 @@ namespace Sylius\Component\Core\Currency;
|
|||
|
||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||
use Sylius\Component\Currency\Context\CurrencyNotFoundException;
|
||||
use Sylius\Component\Storage\StorageInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* @author Kamil Kokot <kamil.kokot@lakion.com>
|
||||
*/
|
||||
final class CurrencyStorage implements CurrencyStorageInterface
|
||||
final class SessionBasedCurrencyStorage implements CurrencyStorageInterface
|
||||
{
|
||||
/**
|
||||
* @var StorageInterface
|
||||
* @var SessionInterface
|
||||
*/
|
||||
private $storage;
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @param StorageInterface $storage
|
||||
* @param SessionInterface $session
|
||||
*/
|
||||
public function __construct(StorageInterface $storage)
|
||||
public function __construct(SessionInterface $session)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +38,7 @@ final class CurrencyStorage implements CurrencyStorageInterface
|
|||
*/
|
||||
public function set(ChannelInterface $channel, $currencyCode)
|
||||
{
|
||||
$this->storage->setData($this->provideKey($channel), $currencyCode);
|
||||
$this->session->set($this->provideKey($channel), $currencyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +46,7 @@ final class CurrencyStorage implements CurrencyStorageInterface
|
|||
*/
|
||||
public function get(ChannelInterface $channel)
|
||||
{
|
||||
$currencyCode = $this->storage->getData($this->provideKey($channel));
|
||||
$currencyCode = $this->session->get($this->provideKey($channel));
|
||||
if (null === $currencyCode) {
|
||||
throw new CurrencyNotFoundException('No currency is set for current channel!');
|
||||
}
|
||||
|
|
@ -13,24 +13,24 @@ namespace Sylius\Component\Core\Locale;
|
|||
|
||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||
use Sylius\Component\Locale\Context\LocaleNotFoundException;
|
||||
use Sylius\Component\Storage\StorageInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* @author Kamil Kokot <kamil.kokot@lakion.com>
|
||||
*/
|
||||
final class LocaleStorage implements LocaleStorageInterface
|
||||
final class SessionBasedLocaleStorage implements LocaleStorageInterface
|
||||
{
|
||||
/**
|
||||
* @var StorageInterface
|
||||
* @var SessionInterface
|
||||
*/
|
||||
private $storage;
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @param StorageInterface $storage
|
||||
* @param SessionInterface $session
|
||||
*/
|
||||
public function __construct(StorageInterface $storage)
|
||||
public function __construct(SessionInterface $session)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +38,7 @@ final class LocaleStorage implements LocaleStorageInterface
|
|||
*/
|
||||
public function set(ChannelInterface $channel, $localeCode)
|
||||
{
|
||||
$this->storage->setData($this->provideKey($channel), $localeCode);
|
||||
$this->session->set($this->provideKey($channel), $localeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +46,7 @@ final class LocaleStorage implements LocaleStorageInterface
|
|||
*/
|
||||
public function get(ChannelInterface $channel)
|
||||
{
|
||||
$localeCode = $this->storage->getData($this->provideKey($channel));
|
||||
$localeCode = $this->session->get($this->provideKey($channel));
|
||||
if (null === $localeCode) {
|
||||
throw new LocaleNotFoundException('No locale is set for current channel!');
|
||||
}
|
||||
|
|
@ -40,7 +40,6 @@
|
|||
"sylius/registry": "^1.0",
|
||||
"sylius/resource": "^1.0",
|
||||
"sylius/shipping": "^1.0",
|
||||
"sylius/storage": "^1.0",
|
||||
"sylius/taxation": "^1.0",
|
||||
"sylius/taxonomy": "^1.0",
|
||||
"sylius/user": "^1.0",
|
||||
|
|
|
|||
|
|
@ -3,30 +3,27 @@
|
|||
namespace spec\Sylius\Component\Core\Currency;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Currency\CurrencyStorage;
|
||||
use Sylius\Component\Core\Currency\SessionBasedCurrencyStorage;
|
||||
use Sylius\Component\Core\Currency\CurrencyStorageInterface;
|
||||
use Sylius\Component\Currency\Context\CurrencyNotFoundException;
|
||||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Sylius\Component\Storage\StorageInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* @mixin CurrencyStorage
|
||||
* @mixin SessionBasedCurrencyStorage
|
||||
*
|
||||
* @author Kamil Kokot <kamil.kokot@lakion.com>
|
||||
*/
|
||||
final class CurrencyStorageSpec extends ObjectBehavior
|
||||
final class SessionBasedCurrencyStorageSpec extends ObjectBehavior
|
||||
{
|
||||
function let(StorageInterface $storage)
|
||||
function let(SessionInterface $session)
|
||||
{
|
||||
$this->beConstructedWith($storage);
|
||||
$this->beConstructedWith($session);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Core\Currency\CurrencyStorage');
|
||||
$this->shouldHaveType(SessionBasedCurrencyStorage::class);
|
||||
}
|
||||
|
||||
function it_is_a_currency_storage()
|
||||
|
|
@ -35,35 +32,34 @@ final class CurrencyStorageSpec extends ObjectBehavior
|
|||
}
|
||||
|
||||
function it_sets_currency_for_given_channel(
|
||||
StorageInterface $storage,
|
||||
SessionInterface $session,
|
||||
ChannelInterface $channel
|
||||
) {
|
||||
$channel->getCode()->willReturn('web');
|
||||
|
||||
$storage->setData('_currency_web', 'BTC')->shouldBeCalled();
|
||||
$session->set('_currency_web', 'BTC')->shouldBeCalled();
|
||||
|
||||
$this->set($channel, 'BTC');
|
||||
}
|
||||
|
||||
function it_gets_currency_for_given_channel(
|
||||
StorageInterface $storage,
|
||||
ChannelInterface $channel,
|
||||
CurrencyInterface $currency
|
||||
SessionInterface $session,
|
||||
ChannelInterface $channel
|
||||
) {
|
||||
$channel->getCode()->willReturn('web');
|
||||
|
||||
$storage->getData('_currency_web')->willReturn('BTC');
|
||||
$session->get('_currency_web')->willReturn('BTC');
|
||||
|
||||
$this->get($channel)->shouldReturn('BTC');
|
||||
}
|
||||
|
||||
function it_throws_a_currency_not_found_exception_if_storage_does_not_have_currency_code_for_given_channel(
|
||||
StorageInterface $storage,
|
||||
SessionInterface $session,
|
||||
ChannelInterface $channel
|
||||
) {
|
||||
$channel->getCode()->willReturn('web');
|
||||
|
||||
$storage->getData('_currency_web')->willReturn(null);
|
||||
$session->get('_currency_web')->willReturn(null);
|
||||
|
||||
$this->shouldThrow(CurrencyNotFoundException::class)->during('get', [$channel]);
|
||||
}
|
||||
|
|
@ -4,26 +4,26 @@ namespace spec\Sylius\Component\Core\Locale;
|
|||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Locale\LocaleStorage;
|
||||
use Sylius\Component\Core\Locale\SessionBasedLocaleStorage;
|
||||
use Sylius\Component\Core\Locale\LocaleStorageInterface;
|
||||
use Sylius\Component\Locale\Context\LocaleNotFoundException;
|
||||
use Sylius\Component\Storage\StorageInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* @mixin LocaleStorage
|
||||
* @mixin SessionBasedLocaleStorage
|
||||
*
|
||||
* @author Kamil Kokot <kamil.kokot@lakion.com>
|
||||
*/
|
||||
final class LocaleStorageSpec extends ObjectBehavior
|
||||
final class SessionBasedLocaleStorageSpec extends ObjectBehavior
|
||||
{
|
||||
function let(StorageInterface $storage)
|
||||
function let(SessionInterface $session)
|
||||
{
|
||||
$this->beConstructedWith($storage);
|
||||
$this->beConstructedWith($session);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType(LocaleStorage::class);
|
||||
$this->shouldHaveType(SessionBasedLocaleStorage::class);
|
||||
}
|
||||
|
||||
function it_is_a_locale_storage()
|
||||
|
|
@ -32,34 +32,34 @@ final class LocaleStorageSpec extends ObjectBehavior
|
|||
}
|
||||
|
||||
function it_sets_locale_for_given_channel(
|
||||
StorageInterface $storage,
|
||||
SessionInterface $session,
|
||||
ChannelInterface $channel
|
||||
) {
|
||||
$channel->getCode()->willReturn('web');
|
||||
|
||||
$storage->setData('_locale_web', 'BTC')->shouldBeCalled();
|
||||
$session->set('_locale_web', 'BTC')->shouldBeCalled();
|
||||
|
||||
$this->set($channel, 'BTC');
|
||||
}
|
||||
|
||||
function it_gets_locale_for_given_channel(
|
||||
StorageInterface $storage,
|
||||
SessionInterface $session,
|
||||
ChannelInterface $channel
|
||||
) {
|
||||
$channel->getCode()->willReturn('web');
|
||||
|
||||
$storage->getData('_locale_web')->willReturn('BTC');
|
||||
$session->get('_locale_web')->willReturn('BTC');
|
||||
|
||||
$this->get($channel)->shouldReturn('BTC');
|
||||
}
|
||||
|
||||
function it_throws_a_locale_not_found_exception_if_storage_does_not_have_locale_code_for_given_channel(
|
||||
StorageInterface $storage,
|
||||
SessionInterface $session,
|
||||
ChannelInterface $channel
|
||||
) {
|
||||
$channel->getCode()->willReturn('web');
|
||||
|
||||
$storage->getData('_locale_web')->willReturn(null);
|
||||
$session->get('_locale_web')->willReturn(null);
|
||||
|
||||
$this->shouldThrow(LocaleNotFoundException::class)->during('get', [$channel]);
|
||||
}
|
||||
5
src/Sylius/Component/Storage/.gitignore
vendored
5
src/Sylius/Component/Storage/.gitignore
vendored
|
|
@ -1,5 +0,0 @@
|
|||
vendor/
|
||||
bin/
|
||||
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
CHANGELOG
|
||||
=========
|
||||
|
||||
### v0.12.0
|
||||
|
||||
* Initial dev release.
|
||||
|
|
@ -1,65 +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\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @author Joseph Bielawski <stloyd@gmail.com>
|
||||
*/
|
||||
class CookieStorage implements StorageInterface
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData($key)
|
||||
{
|
||||
return $this->request->cookies->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData($key, $default = null)
|
||||
{
|
||||
return $this->request->cookies->get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setData($key, $value)
|
||||
{
|
||||
$this->request->cookies->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeData($key)
|
||||
{
|
||||
$this->request->cookies->remove($key);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +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\Storage;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
|
||||
/**
|
||||
* @author Joseph Bielawski <stloyd@gmail.com>
|
||||
*/
|
||||
class DoctrineCacheStorage implements StorageInterface
|
||||
{
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
public function __construct(Cache $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData($key)
|
||||
{
|
||||
return $this->cache->contains($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData($key, $default = null)
|
||||
{
|
||||
$data = $this->cache->fetch($key);
|
||||
if ($data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setData($key, $value)
|
||||
{
|
||||
$this->cache->save($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeData($key)
|
||||
{
|
||||
$this->cache->delete($key);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,47 +0,0 @@
|
|||
Storage Component [](http://travis-ci.org/Sylius/Storage)
|
||||
=================
|
||||
|
||||
Component allowing easily & unified storage handling for PHP applications.
|
||||
|
||||
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/Storage/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://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/Storage/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/Currency/contributors).
|
||||
|
|
@ -1,64 +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\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
* @author Joseph Bielawski <stloyd@gmail.com>
|
||||
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
|
||||
*/
|
||||
class SessionStorage implements StorageInterface
|
||||
{
|
||||
/**
|
||||
* @var SessionInterface
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
public function __construct(SessionInterface $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasData($key)
|
||||
{
|
||||
return $this->session->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData($key, $default = null)
|
||||
{
|
||||
return $this->session->get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setData($key, $value)
|
||||
{
|
||||
$this->session->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeData($key)
|
||||
{
|
||||
$this->session->remove($key);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +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\Storage;
|
||||
|
||||
/**
|
||||
* @author Joseph Bielawski <stloyd@gmail.com>
|
||||
*/
|
||||
interface StorageInterface
|
||||
{
|
||||
/**
|
||||
* Checks that data exists in storage.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasData($key);
|
||||
|
||||
/**
|
||||
* Returns data from storage or the default one.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData($key, $default = null);
|
||||
|
||||
/**
|
||||
* Sets data in storage.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setData($key, $value);
|
||||
|
||||
/**
|
||||
* Remove data from storage.
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function removeData($key);
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
{
|
||||
"name": "sylius/storage",
|
||||
"type": "library",
|
||||
"description": "Component allowing easily & unified storage handling for PHP applications.",
|
||||
"keywords": ["storage"],
|
||||
"homepage": "http://sylius.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paweł Jędrzejewski",
|
||||
"homepage": "http://pjedrzejewski.com"
|
||||
},
|
||||
{
|
||||
"name": "Sylius project",
|
||||
"homepage": "http://sylius.org"
|
||||
},
|
||||
{
|
||||
"name": "Community contributions",
|
||||
"homepage": "http://github.com/Sylius/Sylius/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^5.6|^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^3.0",
|
||||
"doctrine/cache": "~1.3",
|
||||
"symfony/http-foundation": "^2.8"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Sylius\\Component\\Storage\\": "" }
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": { "Sylius\\Component\\Storage\\spec\\": "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\Component\Storage
|
||||
psr4_prefix: Sylius\Component\Storage
|
||||
src_path: .
|
||||
|
|
@ -1,55 +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\Storage;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Storage\StorageInterface;
|
||||
|
||||
final class DoctrineCacheStorageSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Cache $cache)
|
||||
{
|
||||
$this->beConstructedWith($cache);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Storage\DoctrineCacheStorage');
|
||||
}
|
||||
|
||||
function it_implements_Sylius_storage_interface()
|
||||
{
|
||||
$this->shouldImplement(StorageInterface::class);
|
||||
}
|
||||
|
||||
function it_gets_default_data_if_no_record_was_found($cache)
|
||||
{
|
||||
$cache->fetch('key')->willReturn(null);
|
||||
|
||||
$this->getData('key', 'default')->shouldReturn('default');
|
||||
}
|
||||
|
||||
function it_gets_data_if_found($cache)
|
||||
{
|
||||
$cache->fetch('key')->willReturn('data');
|
||||
|
||||
$this->getData('key', 'default')->shouldReturn('data');
|
||||
}
|
||||
|
||||
function it_sets_data($cache)
|
||||
{
|
||||
$cache->save('key', 'data')->shouldBeCalled();
|
||||
|
||||
$this->setData('key', 'data');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +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\Storage;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Storage\StorageInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
|
||||
final class SessionStorageSpec extends ObjectBehavior
|
||||
{
|
||||
function let(SessionInterface $session)
|
||||
{
|
||||
$this->beConstructedWith($session);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Sylius\Component\Storage\SessionStorage');
|
||||
}
|
||||
|
||||
function it_implements_Sylius_storage_interface()
|
||||
{
|
||||
$this->shouldImplement(StorageInterface::class);
|
||||
}
|
||||
|
||||
function it_gets_default_data_if_session_was_not_started($session)
|
||||
{
|
||||
$session->isStarted()->willReturn(false);
|
||||
$session->get('key', 'default')->willReturn('default');
|
||||
|
||||
$this->getData('key', 'default')->shouldReturn('default');
|
||||
}
|
||||
|
||||
function it_gets_default_data_if_no_record_was_found($session)
|
||||
{
|
||||
$session->isStarted()->willReturn(true);
|
||||
$session->get('key', 'default')->willReturn('default');
|
||||
|
||||
$this->getData('key', 'default')->shouldReturn('default');
|
||||
}
|
||||
|
||||
function it_gets_data_if_found($session)
|
||||
{
|
||||
$session->isStarted()->willReturn(true);
|
||||
$session->get('key', 'default')->willReturn('data');
|
||||
|
||||
$this->getData('key', 'default')->shouldReturn('data');
|
||||
}
|
||||
|
||||
function it_sets_data($session)
|
||||
{
|
||||
$session->set('key', 'data')->shouldBeCalled();
|
||||
|
||||
$this->setData('key', 'data');
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
"doctrine/collections": "^1.1",
|
||||
"sylius/resource": "^1.0",
|
||||
"sylius/storage": "^1.0",
|
||||
"symfony/security": "^2.8",
|
||||
"symfony/polyfill-mbstring": "~1.0"
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue