Skip to content

Commit

Permalink
Renamed SessionRegistry to AbstractSession, Added ci configs & first …
Browse files Browse the repository at this point in the history
…documentation
  • Loading branch information
hollodotme committed Jul 5, 2016
1 parent a4bc680 commit e67af87
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_name: travis-ci
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ vagrant
vendor/
composer.lock

# tools
build/tools/*.phar

# locally generated docs
build/api/
build/phpdox/
Expand Down
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: php

php:
- 7.0

branches:
only:
- master
- development
- /^feature\/.+$/

before_script:
- git checkout $TRAVIS_BRANCH
- composer self-update
- mkdir -p vendor/bin
- composer install -o --prefer-dist --no-interaction
- mkdir build/logs

script:
- php vendor/bin/phpunit -c build/

after_script:
- php vendor/bin/coveralls -c ./.coveralls.yml -v --exclude-no-stmt
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ We accept contributions via pull requests on [GitHub](https://github.com/icehawk

## Running Tests

$ php build/tools/phpunit.phar -c build
$ vendor/bin/phpunit -c build/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 IceHawk
Copyright (c) 2016 Holger Woltersdorf and 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
Expand Down
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
[![Build Status](https://travis-ci.org/icehawk/session.svg?branch=master)](https://travis-ci.org/icehawk/session)
[![Coverage Status](https://coveralls.io/repos/github/icehawk/session/badge.svg?branch=master)](https://coveralls.io/github/icehawk/session?branch=master)
[![Latest Stable Version](https://poser.pugx.org/icehawk/session/v/stable)](https://packagist.org/packages/icehawk/session)
[![Total Downloads](https://poser.pugx.org/icehawk/session/downloads)](https://packagist.org/packages/icehawk/session)
[![Latest Unstable Version](https://poser.pugx.org/icehawk/session/v/unstable)](https://packagist.org/packages/icehawk/session)
[![License](https://poser.pugx.org/icehawk/session/license)](https://packagist.org/packages/icehawk/session)

# IceHawk\Session

Session registry component for IceHawk framework

## Intention

This component is intended to wrap the super-global `$_SESSION` variable and give
access to values by explicitly user-defined keys and value/return types
and is therefor declared abstract.

Furthermore it provides the registration and interfaces for data mappers on all, several or single keys, e.g. to reduce data overhead stored in session.

## Usage

### Extend the class `AbstractSession`

```php
<?php declare(strict_types=1);

namespace Vendor\Project;

use IceHawk\Session\AbstractSession;

final class Session extends AbstractSession
{
const KEY_SOME_STRING_VALUE = 'someStringValue';

public function getSomeStringValue() : string
{
return $this->get( self::KEY_SOME_STRING_VALUE );
}

public function setSomeStringValue( string $value )
{
$this->set( self::KEY_SOME_STRING_VALUE, $value );
}

public function isSomeStringValueSet() : bool
{
return $this->isset( self::KEY_SOME_STRING_VALUE );
}

public function unsetSomeStringValue()
{
$this->unset( self::KEY_SOME_STRING_VALUE );
}
}
```

### Work with values

```php
<?php declare(strict_types=1);

namespace Vendor\Project;

$session = new Session( $_SESSION );

# Set
$session->setSomeStringValue( 'Hello world' );

# Isset
if ( $session->isSomeStringValueSet() )
{
# Get
$someString = $session->getSomeStringValue();

echo $someString . ' was set.';
}

# Unset
$session->unsetSomeStringValue();
```
7 changes: 7 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
VAGRANTFILE_API_VERSION = "2"

$script = <<SCRIPT
curl -sS 'https://getcomposer.org/installer' | php -- --install-dir=/usr/local/bin --filename=composer
chmod +x /usr/local/bin/composer
SCRIPT

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# box-config
Expand All @@ -19,4 +24,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# hostname
config.vm.hostname = "IceHawkSession"

config.vm.provision "shell", inline: $script

end
33 changes: 0 additions & 33 deletions build/tools/update_tools.sh

This file was deleted.

43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"require": {
"php": ">=7.0"
},
"require-dev": {
"tm/tooly-composer-script": "^0.1.1"
},
"autoload": {
"psr-4": {
"IceHawk\\Session\\": "src/"
Expand All @@ -26,5 +29,45 @@
"psr-4": {
"IceHawk\\Session\\Tests\\Unit\\": "tests/Unit/"
}
},
"scripts": {
"post-install-cmd": "Tooly\\ScriptHandler::installPharTools",
"post-update-cmd": "Tooly\\ScriptHandler::installPharTools"
},
"extra": {
"tools": {
"phpunit": {
"url": "https://phar.phpunit.de/phpunit.phar",
"only-dev": true
},
"phploc": {
"url": "https://phar.phpunit.de/phploc.phar",
"only-dev": true
},
"pdepend": {
"url": "https://static.pdepend.org/php/latest/pdepend.phar",
"only-dev": true
},
"phpmd": {
"url": "https://static.phpmd.org/php/latest/phpmd.phar",
"only-dev": true
},
"phpcs": {
"url": "https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar",
"only-dev": true
},
"phpcpd": {
"url": "https://phar.phpunit.de/phpcpd.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
}
}
}
}
4 changes: 2 additions & 2 deletions src/SessionRegistry.php → src/AbstractSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use IceHawk\Session\Interfaces\MapsSessionData;

/**
* Class SessionRegistry
* Class AbstractSession
* @package IceHawk\Session
*/
class SessionRegistry
abstract class AbstractSession
{
/** @var array */
private $sessionData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use IceHawk\Session\Tests\Unit\Fixtures\DataMapper;
use IceHawk\Session\Tests\Unit\Fixtures\Session;

class SessionRegistryTest extends \PHPUnit_Framework_TestCase
class AbstractSessionTest extends \PHPUnit_Framework_TestCase
{
public function testCanSetValue()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Fixtures/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

namespace IceHawk\Session\Tests\Unit\Fixtures;

use IceHawk\Session\SessionRegistry;
use IceHawk\Session\AbstractSession;

/**
* Class Session
* @package IceHawk\Session\Tests\Unit\Fixtures
*/
final class Session extends SessionRegistry
final class Session extends AbstractSession
{
const UNIT_TEST_KEY = 'unitTestKey';

Expand Down

0 comments on commit e67af87

Please sign in to comment.