├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── appveyor.yml ├── composer.json ├── phpunit.xml.dist ├── spec └── Isolate │ ├── IsolateSpec.php │ └── PersistenceContext │ └── NameSpec.php └── src └── Isolate ├── ContextRegistry.php ├── Exception ├── Exception.php ├── InvalidArgumentException.php ├── NotClosedTransactionException.php └── NotOpenedTransactionException.php ├── Isolate.php ├── PersistenceContext.php └── PersistenceContext ├── Factory.php ├── Name.php ├── Transaction.php └── Transaction └── Factory.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | /bin/ 3 | composer.lock 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | matrix: 4 | include: 5 | - php: 5.4 6 | env: DEPENDENCIES='low' 7 | - php: 5.4 8 | - php: 5.5 9 | - php: 5.6 10 | - php: hhvm 11 | - php: hhvm-nightly 12 | allow_failures: 13 | - php: hhvm-nightly 14 | - env: DEPENDENCIES='low' 15 | 16 | before_install: 17 | - composer self-update 18 | 19 | install: 20 | - export COMPOSER_ROOT_VERSION=dev-master 21 | - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; 22 | - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; 23 | 24 | script: 25 | - ./bin/phpspec run --format=pretty 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Norbert Orzechowicz 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Isolate 2 | 3 | [![Build Status](https://travis-ci.org/isolate-org/isolate.svg?branch=master)](https://travis-ci.org/isolate-org/isolate) 4 | [![Windows Build status](https://ci.appveyor.com/api/projects/status/7xakomo680t49x16?svg=true)](https://ci.appveyor.com/project/norzechowicz/isolate) 5 | [![Latest Stable Version](https://poser.pugx.org/isolate/isolate/v/stable.svg)](https://packagist.org/packages/isolate/isolate) 6 | [![Total Downloads](https://poser.pugx.org/isolate/isolate/downloads.svg)](https://packagist.org/packages/isolate/isolate) 7 | [![Latest Unstable Version](https://poser.pugx.org/isolate/isolate/v/unstable.svg)](https://packagist.org/packages/isolate/isolate) 8 | [![License](https://poser.pugx.org/isolate/isolate/license.svg)](https://packagist.org/packages/isolate/isolate) 9 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/isolate-org/isolate/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/isolate-org/isolate/?branch=master) 10 | 11 | ## Documentation 12 | 13 | To find out how to use Isolate follow [Documentation] 14 | 15 | ## Support 16 | 17 | If you have any problems or questions your can always contact us on Twitter, just tweet to [@isolate_php] 18 | 19 | ## License 20 | 21 | All Isolate components are released under [MIT license] 22 | 23 | [Documentation]: http://docs.isolate-project.org/en/latest/index.html 24 | [@isolate_php]: https://twitter.com/isolate_php 25 | [MIT license]: LICENSE 26 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | build: false 2 | shallow_clone: true 3 | platform: x86 4 | clone_folder: c:\projects\isolate\isolate 5 | 6 | init: 7 | - SET COMPOSER_NO_INTERACTION=1 8 | 9 | install: 10 | - cinst -y php 11 | - cd c:\tools\php 12 | - copy php.ini-production php.ini 13 | - echo date.timezone="UTC" >> php.ini 14 | - echo extension=php_curl.dll >> php.ini 15 | - echo extension_dir=ext >> php.ini 16 | - SET PATH=C:\tools\php;%PATH% 17 | - cd c:\projects\isolate\isolate 18 | - appveyor DownloadFile https://getcomposer.org/composer.phar 19 | - php composer.phar update --prefer-source --no-progress --ansi 20 | 21 | test_script: 22 | - cd c:\projects\isolate\isolate 23 | - bin\phpspec run --format=dot --ansi -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "isolate/isolate", 3 | "description": "Isolate is an abstraction layer for data persistence. Operations related to tracking changes and saving data are done in transactions which makes your code not aware of sotrage type.", 4 | "keywords": ["isolate", "orm", "framework", "storage", "data", "odm"], 5 | "require": { 6 | "php": ">=5.4.0" 7 | }, 8 | "require-dev": { 9 | "phpspec/phpspec": "^2" 10 | }, 11 | "autoload": { 12 | "psr-0": { 13 | "Isolate": "src/" 14 | } 15 | }, 16 | "extra": { 17 | "branch-alias": { 18 | "dev-master": "1.0-dev" 19 | } 20 | }, 21 | "config": { 22 | "bin-dir": "bin" 23 | }, 24 | "license": "MIT", 25 | "authors": [ 26 | { 27 | "name": "Norbert Orzechowicz", 28 | "email": "norbert@orzechowicz.pl" 29 | } 30 | ], 31 | "suggest": { 32 | "isolate/framework": "Framework integrate Isolate components. Read more at http://docs.isolate-project.org/en/latest/framework/index.html" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | 20 | ./src/Isolate/ 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /spec/Isolate/IsolateSpec.php: -------------------------------------------------------------------------------- 1 | create(Argument::type('Isolate\PersistenceContext\Name'))->willReturn($context); 16 | $context->openTransaction()->willReturn($transaction); 17 | 18 | $this->beConstructedWith($contextFactory); 19 | } 20 | 21 | function it_is_persistence_context_registry() 22 | { 23 | $this->shouldImplement("Isolate\\ContextRegistry"); 24 | } 25 | 26 | function it_creates_context_only_when_it_does_not_exists(Factory $contextFactory, PersistenceContext $context) 27 | { 28 | $contextFactory->create(Argument::type('Isolate\PersistenceContext\Name'))->shouldBecalledTimes(1); 29 | 30 | $this->getContext('database')->shouldReturnAnInstanceOf('Isolate\\PersistenceContext'); 31 | $this->getContext('database')->shouldReturnAnInstanceOf('Isolate\\PersistenceContext'); 32 | } 33 | 34 | function it_open_transaction_on_context() 35 | { 36 | $this->openTransaction()->shouldReturnAnInstanceOf("Isolate\\PersistenceContext\\Transaction"); 37 | } 38 | 39 | function it_close_transaction_on_context(PersistenceContext $context) 40 | { 41 | $context->closeTransaction()->shouldBeCalled(); 42 | 43 | $this->closeTransaction(); 44 | } 45 | 46 | function it_knows_if_has_open_transaction(PersistenceContext $context) 47 | { 48 | $context->hasOpenTransaction()->willReturn(true); 49 | 50 | $this->hasOpenTransaction()->shouldReturn(true); 51 | } 52 | 53 | function it_returns_open_transaction(PersistenceContext $context, Transaction $transaction) 54 | { 55 | $context->getTransaction()->willReturn($transaction); 56 | 57 | $this->getTransaction()->shouldReturnAnInstanceOf("Isolate\\PersistenceContext\\Transaction"); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /spec/Isolate/PersistenceContext/NameSpec.php: -------------------------------------------------------------------------------- 1 | shouldThrow( 14 | new InvalidArgumentException() 15 | )->during("__construct", [new \stdClass()]); 16 | } 17 | 18 | function it_throws_exception_when_created_from_empty_string() 19 | { 20 | $this->shouldThrow( 21 | new InvalidArgumentException() 22 | )->during("__construct", [""]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Isolate/ContextRegistry.php: -------------------------------------------------------------------------------- 1 | contextFactory = $contextFactory; 26 | $this->contexts = []; 27 | } 28 | 29 | /** 30 | * {inheritdoc} 31 | */ 32 | public function getContext($name = self::DEFAULT_CONTEXT) 33 | { 34 | if (!array_key_exists($name, $this->contexts)) { 35 | $this->contexts[$name] = $this->contextFactory->create(new Name($name)); 36 | } 37 | 38 | return $this->contexts[$name]; 39 | } 40 | 41 | /** 42 | * {inheritdoc} 43 | */ 44 | public function openTransaction($name = self::DEFAULT_CONTEXT) 45 | { 46 | return $this->getContext($name)->openTransaction(); 47 | } 48 | 49 | /** 50 | * {inheritdoc} 51 | */ 52 | public function closeTransaction($name = self::DEFAULT_CONTEXT) 53 | { 54 | $this->getContext($name)->closeTransaction(); 55 | } 56 | 57 | /** 58 | * {inheritdoc} 59 | */ 60 | public function hasOpenTransaction($name = self::DEFAULT_CONTEXT) 61 | { 62 | return $this->getContext($name)->hasOpenTransaction(); 63 | } 64 | 65 | /** 66 | * {inheritdoc} 67 | */ 68 | public function getTransaction($name = self::DEFAULT_CONTEXT) 69 | { 70 | return $this->getContext($name)->getTransaction(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Isolate/PersistenceContext.php: -------------------------------------------------------------------------------- 1 | name = $name; 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | public function __toString() 34 | { 35 | return $this->name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Isolate/PersistenceContext/Transaction.php: -------------------------------------------------------------------------------- 1 |