diff --git a/CHANGELOG.md b/CHANGELOG.md index 1921c46..5f112d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a CHANGELOG](http://keepachangelog.com). -## [Unreleased] +## [1.0.0] - 2016-11-20 +- First stable release -[Unreleased](https://github.com/icehawk/session-forms-bridge/blob/master) +[1.0.0]: https://github.com/icehawk/session-forms-bridge/tree/v1.0.0 diff --git a/README.md b/README.md index 377d53c..abb7ff4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Build Status](https://travis-ci.org/icehawk/session-forms-bridge.svg?branch=master)](https://travis-ci.org/icehawk/session-forms-bridge) [![Coverage Status](https://coveralls.io/repos/github/icehawk/session-forms-bridge/badge.svg?branch=master)](https://coveralls.io/github/icehawk/session-forms-bridge?branch=master) +[![Dependency Status](https://www.versioneye.com/user/projects/58321b484ef164004c24272f/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/58321b484ef164004c24272f) [![Latest Stable Version](https://poser.pugx.org/icehawk/session-forms-bridge/v/stable)](https://packagist.org/packages/icehawk/session-forms-bridge) [![Total Downloads](https://poser.pugx.org/icehawk/session-forms-bridge/downloads)](https://packagist.org/packages/icehawk/session-forms-bridge) [![Latest Unstable Version](https://poser.pugx.org/icehawk/session-forms-bridge/v/unstable)](https://packagist.org/packages/icehawk/session-forms-bridge) @@ -9,3 +10,35 @@ A bridge implementation to combine the IceHawk components Session and Forms. +This package provides one class named `AbstractSession` that extends the original `AbstractSession` class from the +[IceHawk Session component](https://github.com/icehawk/session) to combine it with the +[IceHawk Forms component](https://github.com/icehawk/forms). + +This bridge package is intended to be used to + +- reduce the dependency definitions in the `composer.json` +- Add relevant methods to retrieve or unset `Form` instances + +## Added methods + +```php +public function getForm( IdentifiesForm $formId ) : Form +``` + +This method returns a new or existing `Form` instance from the session wrapper an guaranties that you always get the same instance for the same `$formId`. + +```php +public function unsetForm( IdentifiesForm $formId ) +``` + +This method removes an existing `Form` instance from the session data. + +```php +public function unsetAllForms() +``` + +This method removes all existing `Form` instances from the session data. + +## More documentation + +Read more about the IceHawk components Session and Forms in our documentation at **[icehawk.github.io](https://icehawk.github.io)**. diff --git a/build/phpmd.xml b/build/phpmd.xml deleted file mode 100644 index ec726e3..0000000 --- a/build/phpmd.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - SessionFormsBridge ruleset - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/composer.json b/composer.json index 3241d83..9563330 100644 --- a/composer.json +++ b/composer.json @@ -6,14 +6,17 @@ "license": "MIT", "authors": [ { - "name": "hollodotme" + "name": "Holger Woltersdorf", + "email": "hw@hollo.me" } ], "support": { "source": "https://github.com/icehawk/session-forms-bridge" }, "require": { - "php": ">=7.0" + "php": ">=7.0", + "icehawk/session": "^1.0", + "icehawk/forms": "^1.0" }, "require-dev": { "tm/tooly-composer-script": "^1.0" @@ -52,4 +55,4 @@ } } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..2378dbf --- /dev/null +++ b/composer.lock @@ -0,0 +1,219 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "026b667686afa80462371b848971da19", + "content-hash": "5a1386988326cfc8f353c4b9a144ba11", + "packages": [ + { + "name": "icehawk/forms", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/icehawk/forms.git", + "reference": "e5a95920af7afadeed9337ad2b0f03a6949ddf7c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/icehawk/forms/zipball/e5a95920af7afadeed9337ad2b0f03a6949ddf7c", + "reference": "e5a95920af7afadeed9337ad2b0f03a6949ddf7c", + "shasum": "" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "tm/tooly-composer-script": "^1.0" + }, + "type": "library", + "extra": { + "tools": { + "phpunit": { + "url": "https://phar.phpunit.de/phpunit.phar", + "only-dev": true + }, + "phpmetrics": { + "url": "https://github.com/phpmetrics/PhpMetrics/raw/master/build/phpmetrics.phar", + "only-dev": true + }, + "phpdox": { + "url": "https://github.com/theseer/phpdox/releases/download/0.8.1.1/phpdox-0.8.1.1.phar", + "only-dev": true + }, + "coveralls": { + "url": "https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar", + "only-dev": true + } + } + }, + "autoload": { + "psr-4": { + "IceHawk\\Forms\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Holger Woltersdorf", + "email": "hw@hollo.me" + } + ], + "description": "Forms component for the IceHawk framework", + "time": "2016-10-06 22:50:03" + }, + { + "name": "icehawk/session", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://github.com/icehawk/session.git", + "reference": "ac54cb5fd0fd61f6f0211fe3ec736c41c49195de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/icehawk/session/zipball/ac54cb5fd0fd61f6f0211fe3ec736c41c49195de", + "reference": "ac54cb5fd0fd61f6f0211fe3ec736c41c49195de", + "shasum": "" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "tm/tooly-composer-script": "^1.0" + }, + "type": "library", + "extra": { + "tools": { + "phpunit": { + "url": "https://phar.phpunit.de/phpunit.phar", + "only-dev": true + }, + "phpmetrics": { + "url": "https://github.com/phpmetrics/PhpMetrics/raw/master/build/phpmetrics.phar", + "only-dev": true + }, + "phpdox": { + "url": "https://github.com/theseer/phpdox/releases/download/0.8.1.1/phpdox-0.8.1.1.phar", + "only-dev": true + }, + "coveralls": { + "url": "https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar", + "only-dev": true + } + } + }, + "autoload": { + "psr-4": { + "IceHawk\\Session\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Holger Woltersdorf", + "email": "hw@hollo.me" + } + ], + "description": "Session registry component for the IceHawk framework", + "time": "2016-10-06 23:25:14" + } + ], + "packages-dev": [ + { + "name": "tm/tooly-composer-script", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/tommy-muehle/tooly-composer-script.git", + "reference": "be34f34ebd83bd25ee388240fcb1b55f109adb6b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tommy-muehle/tooly-composer-script/zipball/be34f34ebd83bd25ee388240fcb1b55f109adb6b", + "reference": "be34f34ebd83bd25ee388240fcb1b55f109adb6b", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "require-dev": { + "codeclimate/php-test-reporter": "dev-master", + "composer/composer": "1.*", + "mikey179/vfsstream": "1.6.*", + "php-mock/php-mock-phpunit": "1.1.*", + "tm/gpg-verifier": "1.*" + }, + "suggest": { + "tm/gpg-verifier": "Allows verification over GPG for PHAR tools." + }, + "type": "library", + "extra": { + "tools": { + "phpunit": { + "url": "https://phar.phpunit.de/phpunit-5.5.0.phar" + }, + "phpcpd": { + "url": "https://phar.phpunit.de/phpcpd-2.0.4.phar" + }, + "phpcs": { + "url": "https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar", + "force-replace": true + }, + "phpmd": { + "url": "http://static.phpmd.org/php/latest/phpmd.phar", + "force-replace": true + }, + "security-checker": { + "url": "http://get.sensiolabs.org/security-checker.phar", + "force-replace": true + } + } + }, + "autoload": { + "psr-4": { + "Tooly\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tommy Muehle", + "email": "tommy.muehle@gmail.com", + "homepage": "https://tommy-muehle.de" + } + ], + "description": "Simple composer script to manage phar files.", + "homepage": "https://github.com/tommy-muehle/tooly-composer-script", + "keywords": [ + "composer", + "composer-phar", + "composer-script", + "gpg-verification", + "phar", + "phar-handling", + "phar-management" + ], + "time": "2016-09-13 10:42:40" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": { + "php": ">=7.0" + }, + "platform-dev": [] +} diff --git a/src/AbstractSession.php b/src/AbstractSession.php new file mode 100644 index 0000000..b0c39bb --- /dev/null +++ b/src/AbstractSession.php @@ -0,0 +1,54 @@ +get( self::FORMS ) ? : []; + + if ( !isset($forms[ $formId->toString() ]) ) + { + $forms[ $formId->toString() ] = new Form( $formId ); + $this->set( self::FORMS, $forms ); + } + + return $forms[ $formId->toString() ]; + } + + public function unsetForm( IdentifiesForm $formId ) + { + $forms = $this->get( self::FORMS ) ? : []; + + unset($forms[ $formId->toString() ]); + + $this->set( self::FORMS, $forms ); + } + + public function unsetAllForms() + { + $this->unset( self::FORMS ); + } +} diff --git a/src/Exceptions/SessionFormsBridgeException.php b/src/Exceptions/SessionFormsBridgeException.php deleted file mode 100644 index 27a561b..0000000 --- a/src/Exceptions/SessionFormsBridgeException.php +++ /dev/null @@ -1,23 +0,0 @@ - []]; + $this->sessionData = &$sessionData; + $this->sessionInstance = new class($sessionData) extends AbstractSession + { + }; + } + + public function testCanGetNewFormInstance() + { + $formId = new FormId( 'unit.test' ); + + $this->assertArrayNotHasKey( $formId->toString(), $this->sessionData[ AbstractSession::FORMS ] ); + + $form = $this->sessionInstance->getForm( $formId ); + + $this->assertArrayHasKey( $formId->toString(), $this->sessionData[ AbstractSession::FORMS ] ); + $this->assertSame( $formId, $form->getFormId() ); + $this->assertInstanceOf( Form::class, $form ); + } + + public function testCanGetExistingInstance() + { + $formId = new FormId( 'unit.test' ); + $form = $this->sessionInstance->getForm( $formId ); + + $existingForm = $this->sessionInstance->getForm( $formId ); + $this->assertSame( $form, $existingForm ); + } + + public function testCanUnsetOneForm() + { + $formId = new FormId( 'unit.test' ); + $form = $this->sessionInstance->getForm( $formId ); + + $this->sessionInstance->unsetForm( $formId ); + + $newForm = $this->sessionInstance->getForm( $formId ); + + $this->assertInstanceOf( Form::class, $form ); + $this->assertInstanceOf( Form::class, $newForm ); + $this->assertNotSame( $form, $newForm ); + } + + public function testCanUnsetAllForms() + { + $formId1 = new FormId( 'unit.test.1' ); + $formId2 = new FormId( 'unit.test.2' ); + + $form1 = $this->sessionInstance->getForm( $formId1 ); + $form2 = $this->sessionInstance->getForm( $formId1 ); + + $this->sessionInstance->unsetAllForms(); + + $newForm1 = $this->sessionInstance->getForm( $formId1 ); + $newForm2 = $this->sessionInstance->getForm( $formId2 ); + + $this->assertInstanceOf( Form::class, $form1 ); + $this->assertInstanceOf( Form::class, $form2 ); + $this->assertInstanceOf( Form::class, $newForm1 ); + $this->assertInstanceOf( Form::class, $newForm2 ); + $this->assertNotSame( $form1, $newForm1 ); + $this->assertNotSame( $form2, $newForm2 ); + } +} diff --git a/tests/Unit/SessionFormsBridgeTest.php b/tests/Unit/SessionFormsBridgeTest.php deleted file mode 100644 index 48d7fa9..0000000 --- a/tests/Unit/SessionFormsBridgeTest.php +++ /dev/null @@ -1,23 +0,0 @@ -