Skip to content

Commit 12f9402

Browse files
committed
Initial commit.
0 parents  commit 12f9402

35 files changed

+2638
-0
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Composer
2+
vendor/
3+
coverage/
4+
composer.lock
5+
6+
# OS Generated
7+
.DS_Store*
8+
ehthumbs.db
9+
Icon?
10+
Thumbs.db
11+
*.swp
12+
13+
# PhpStorm
14+
.idea/*

.scrutinizer.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
filter:
2+
excluded_paths:
3+
- 'vendor/*'
4+
- '*/tests/*'
5+
checks:
6+
php:
7+
code_rating: true
8+
remove_extra_empty_lines: true
9+
remove_php_closing_tag: true
10+
remove_trailing_whitespace: true
11+
fix_use_statements:
12+
remove_unused: true
13+
preserve_multiple: false
14+
preserve_blanklines: true
15+
order_alphabetically: true
16+
fix_php_opening_tag: true
17+
fix_linefeed: true
18+
fix_line_ending: true
19+
fix_identation_4spaces: true
20+
fix_doc_comments: true
21+
tools:
22+
external_code_coverage:
23+
timeout: 600
24+
runs: 3
25+
php_code_coverage: false
26+
php_code_sniffer:
27+
config:
28+
standard: PSR2
29+
filter:
30+
paths: ['src']
31+
php_loc:
32+
enabled: true
33+
excluded_dirs: [vendor, tests]
34+
php_cpd:
35+
enabled: true
36+
excluded_dirs: [vendor, tests]

.travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- hhvm
8+
9+
matrix:
10+
allow_failures:
11+
- php: hhvm
12+
13+
before_script:
14+
- curl -s http://getcomposer.org/installer | php
15+
- composer install --prefer-source --no-interaction --dev
16+
17+
after_script:
18+
- wget https://scrutinizer-ci.com/ocular.phar
19+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
20+
21+
script:
22+
phpunit --coverage-text --coverage-clover=coverage.clover

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 RocketTheme
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# ![](https://avatars1.githubusercontent.com/u/1310198?v=2&s=50) RocketTheme Toolbox
2+
3+
[![Latest Version](http://img.shields.io/packagist/v/rockettheme/toolbox.svg?style=flat)](https://packagist.org/packages/rockettheme/toolbox)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)
5+
[![Build Status](https://img.shields.io/travis/rockettheme/toolbox/master.svg?style=flat)](https://travis-ci.org/rockettheme/toolbox)
6+
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/rockettheme/toolbox.svg?style=flat)](https://scrutinizer-ci.com/g/rockettheme/toolbox/code-structure)
7+
[![Quality Score](https://img.shields.io/scrutinizer/g/rockettheme/toolbox.svg?style=flat)](https://scrutinizer-ci.com/g/rockettheme/toolbox)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/rockettheme/toolbox.svg?style=flat)](https://packagist.org/packages/rockettheme/toolbox)
9+
10+
RocketTheme\Toolbox package contains a set of reusable PHP interfaces, classes and traits.
11+
12+
* ArrayTraits
13+
* DI
14+
* Event
15+
* File
16+
* ResourceLocator
17+
* Session
18+
* StreamWrapper
19+
20+
## Installation
21+
22+
You can use [Composer](http://getcomposer.org/) to download and install this package as well as its dependencies.
23+
24+
### Composer
25+
26+
To add this package as a local, per-project dependency to your project, simply add a dependency on `rockettheme/toolbox` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Diff:
27+
28+
{
29+
"require": {
30+
"rockettheme/toolbox": "*"
31+
}
32+
}
33+
34+
35+
# Contributing
36+
37+
We appreciate any contribution to ToolBox, whether it is related to bugs or simply a suggestion or improvement.
38+
However, we ask that any contribution follow our simple guidelines in order to be properly received.
39+
40+
All our projects follow the [GitFlow branching model][gitflow-model], from development to release. If you are not familiar with it, there are several guides and tutorials to make you understand what it is about.
41+
42+
You will probably want to get started by installing [this very good collection of git extensions][gitflow-extensions].
43+
44+
What you mainly want to know is that:
45+
46+
- All the main activity happens in the `develop` branch. Any pull request should be addressed only to that branch. We will not consider pull requests made to the `master`.
47+
- It's very well appreciated, and highly suggested, to start a new feature whenever you want to make changes or add functionalities. It will make it much easier for us to just checkout your feature branch and test it, before merging it into `develop`
48+
49+
50+
# Getting Started
51+
52+
* Have fun!
53+
54+
55+
[gitflow-model]: http://nvie.com/posts/a-successful-git-branching-model/
56+
[gitflow-extensions]: https://github.com/nvie/gitflow
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
namespace RocketTheme\Toolbox\ArrayTraits;
3+
4+
/**
5+
* Implements ArrayAccess interface.
6+
*
7+
* @package RocketTheme\Toolbox\ArrayTraits
8+
* @author RocketTheme
9+
* @license MIT
10+
*
11+
* @property array $items
12+
*/
13+
trait ArrayAccess
14+
{
15+
/**
16+
* Whether or not an offset exists.
17+
*
18+
* @param mixed $offset An offset to check for.
19+
* @return bool Returns TRUE on success or FALSE on failure.
20+
*/
21+
public function offsetExists($offset)
22+
{
23+
return isset($this->items[$offset]);
24+
}
25+
26+
/**
27+
* Returns the value at specified offset.
28+
*
29+
* @param mixed $offset The offset to retrieve.
30+
* @return mixed Can return all value types.
31+
*/
32+
public function offsetGet($offset)
33+
{
34+
return isset($this->items[$offset]) ? $this->items[$offset] : null;
35+
}
36+
37+
/**
38+
* Assigns a value to the specified offset.
39+
*
40+
* @param mixed $offset The offset to assign the value to.
41+
* @param mixed $value The value to set.
42+
*/
43+
public function offsetSet($offset, $value)
44+
{
45+
if (is_null($offset)) {
46+
$this->items[] = $value;
47+
} else {
48+
$this->items[$offset] = $value;
49+
}
50+
}
51+
52+
/**
53+
* Unsets an offset.
54+
*
55+
* @param mixed $offset The offset to unset.
56+
*/
57+
public function offsetUnset($offset)
58+
{
59+
// Hack to make Iterator trait work together with unset.
60+
if (isset($this->iteratorUnset) && $offset == key($this->items)) {
61+
$this->iteratorUnset = true;
62+
}
63+
64+
unset($this->items[$offset]);
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
namespace RocketTheme\Toolbox\ArrayTraits;
3+
4+
/**
5+
* Implements getters and setters.
6+
*
7+
* @package RocketTheme\Toolbox\ArrayTraits
8+
* @author RocketTheme
9+
* @license MIT
10+
*/
11+
trait ArrayAccessWithGetters
12+
{
13+
use ArrayAccess;
14+
15+
/**
16+
* Magic setter method
17+
*
18+
* @param mixed $offset Asset name value
19+
* @param mixed $value Asset value
20+
*/
21+
public function __set($offset, $value)
22+
{
23+
$this->offsetSet($offset, $value);
24+
}
25+
26+
/**
27+
* Magic getter method
28+
*
29+
* @param mixed $offset Asset name value
30+
* @return mixed Asset value
31+
*/
32+
public function __get($offset)
33+
{
34+
return $this->offsetGet($offset);
35+
}
36+
37+
/**
38+
* Magic method to determine if the attribute is set
39+
*
40+
* @param mixed $offset Asset name value
41+
* @return boolean True if the value is set
42+
*/
43+
public function __isset($offset)
44+
{
45+
return $this->offsetExists($offset);
46+
}
47+
48+
/**
49+
* Magic method to unset the attribute
50+
*
51+
* @param mixed $offset The name value to unset
52+
*/
53+
public function __unset($offset)
54+
{
55+
$this->offsetUnset($offset);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace RocketTheme\Toolbox\ArrayTraits;
3+
4+
/**
5+
* Implements Constructor for setting items.
6+
*
7+
* @package RocketTheme\Toolbox\ArrayTraits
8+
* @author RocketTheme
9+
* @license MIT
10+
*
11+
* @property array $items
12+
*/
13+
trait Constructor
14+
{
15+
/**
16+
* Constructor to initialize array.
17+
*
18+
* @param array $items Initial items inside the iterator.
19+
*/
20+
public function __construct(array $items = array())
21+
{
22+
$this->items = $items;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace RocketTheme\Toolbox\ArrayTraits;
3+
4+
/**
5+
* Implements \Countable interface.
6+
*
7+
* @package RocketTheme\Toolbox\ArrayTraits
8+
* @author RocketTheme
9+
* @license MIT
10+
*
11+
* @property array $items
12+
*/
13+
trait Countable
14+
{
15+
/**
16+
* Implements Countable interface.
17+
*
18+
* @return int
19+
*/
20+
public function count()
21+
{
22+
return count($this->items);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace RocketTheme\Toolbox\ArrayTraits;
3+
4+
use Symfony\Component\Yaml\Yaml;
5+
6+
/**
7+
* Implements ExportInterface.
8+
*
9+
* @package RocketTheme\Toolbox\ArrayTraits
10+
* @author RocketTheme
11+
* @license MIT
12+
*
13+
* @property array $items
14+
*/
15+
trait Export
16+
{
17+
/**
18+
* Convert object into an array.
19+
*
20+
* @return array
21+
*/
22+
public function toArray()
23+
{
24+
return $this->items;
25+
}
26+
27+
/**
28+
* Convert object into YAML string.
29+
*
30+
* @return string
31+
*/
32+
public function toYaml()
33+
{
34+
return Yaml::dump($this->toArray());
35+
}
36+
37+
/**
38+
* Convert object into JSON string.
39+
*
40+
* @return string
41+
*/
42+
public function toJson()
43+
{
44+
return json_encode($this->toArray());
45+
}
46+
}

0 commit comments

Comments
 (0)