Skip to content

Commit

Permalink
Added bridge class, added unit test, added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hollodotme committed Nov 20, 2016
1 parent 6445dff commit f4dffac
Show file tree
Hide file tree
Showing 10 changed files with 412 additions and 101 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)**.
27 changes: 0 additions & 27 deletions build/phpmd.xml

This file was deleted.

9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,4 +55,4 @@
}
}
}
}
}
219 changes: 219 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions src/AbstractSession.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php declare(strict_types = 1);
/**
* Copyright (c) 2016 Holger Woltersdorf & Contributors
* 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.
*/

namespace IceHawk\Bridges\SessionForms;

use IceHawk\Forms\Form;
use IceHawk\Forms\Interfaces\IdentifiesForm;
use IceHawk\Session\AbstractSession as BaseSession;

/**
* Class AbstractSession
* @package IceHawk\Bridges\SessionForms
*/
abstract class AbstractSession extends BaseSession
{
const FORMS = 'forms';

public function getForm( IdentifiesForm $formId ) : Form
{
$forms = $this->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 );
}
}
Loading

0 comments on commit f4dffac

Please sign in to comment.