Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit 9f6301a

Browse files
committed
Merge branch 'release/0.4.0'
2 parents ee87a30 + fd41e05 commit 9f6301a

22 files changed

+1454
-432
lines changed

.travis.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
EwbZ91halMei5RU7i08hL57AJqiUzc5UFCjwHwp8oHYxFzz7v/3Vccin7RjT0E+7aPF8MT4rV8Xap4WSFPSgjBrrzaqU06fNPXkUkFv3X4lLkCkjiy635S8+D1sMDtaHY/Ai9p+JZbNf5yROXkzFFOdMBO2ER6Hlvq/3d5QfwxI=
1+
RshLtPfJvPQyIxEsUXlBc/DEfv2uEBvr2gf4Ml6qIbnCjeGUknyhGpjm/oLn4gL0lonTC3gLhT3PVkZG8yTCjFrThnLPucty9LFT4hLfqH2JTSrqYWc57sS3EuaAbjYUo/UtKV9QQTBm3TQYuWGKamzTnNtNM6lITrL19zfcAbM=

.travis.install

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,32 @@
44
* This script is executed before composer dependencies are installed,
55
* and as such must be included in each project as part of the skeleton.
66
*/
7-
if ($token = getenv('ARCHER_TOKEN')) {
8-
$config = array(
9-
'config' => array(
10-
'github-oauth' => array('github.com' => $token)
11-
)
12-
);
137

14-
$file = '~/.composer/config.json';
15-
$dir = dirname($file);
16-
if (!is_dir($dir)) {
17-
mkdir($dir, 0755, true);
18-
}
19-
file_put_contents($file, json_encode($config));
8+
$config = array(
9+
'config' => array(
10+
'notify-on-install' => false
11+
)
12+
);
2013

14+
if ($token = getenv('ARCHER_TOKEN')) {
15+
$config['config']['github-oauth'] = array(
16+
'github.com' => $token
17+
);
2118
$composerFlags = '--prefer-dist';
19+
passthru('curl -s -i -H "Authorization: token $ARCHER_TOKEN" https://api.github.com | grep "^X-RateLimit"');
2220
} else {
2321
$composerFlags = '--prefer-source';
2422
}
2523

26-
passthru('composer install --dev --no-progress --no-interaction --ansi ' . $composerFlags);
24+
$file = '~/.composer/config.json';
25+
$dir = dirname($file);
26+
if (!is_dir($dir)) {
27+
mkdir($dir, 0755, true);
28+
}
29+
file_put_contents($file, json_encode($config));
30+
31+
passthru('composer self-update --no-interaction');
32+
33+
$exitCode = 0;
34+
passthru('composer install --dev --no-progress --no-interaction --ansi ' . $composerFlags, $exitCode);
35+
exit($exitCode);

.travis.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,14 @@
88
#
99
language: php
1010

11-
php:
12-
- 5.3
13-
- 5.4
14-
- 5.5
11+
php: ["5.3", "5.4", "5.5"]
1512

1613
env:
1714
global:
1815
- ARCHER_PUBLISH_VERSION=5.4
19-
- secure: "EwbZ91halMei5RU7i08hL57AJqiUzc5UFCjwHwp8oHYxFzz7v/3Vccin7RjT0E+7aPF8MT4rV8Xap4WSFPSgjBrrzaqU06fNPXkUkFv3X4lLkCkjiy635S8+D1sMDtaHY/Ai9p+JZbNf5yROXkzFFOdMBO2ER6Hlvq/3d5QfwxI="
16+
- secure: "RshLtPfJvPQyIxEsUXlBc/DEfv2uEBvr2gf4Ml6qIbnCjeGUknyhGpjm/oLn4gL0lonTC3gLhT3PVkZG8yTCjFrThnLPucty9LFT4hLfqH2JTSrqYWc57sS3EuaAbjYUo/UtKV9QQTBm3TQYuWGKamzTnNtNM6lITrL19zfcAbM="
2017

2118
install:
2219
- ./.travis.install
2320
script:
2421
- ./vendor/bin/archer travis:build
25-
26-
matrix:
27-
# PHP 5.5 is still in alpha, so ignore build failures.
28-
allow_failures:
29-
- php: 5.5

CHANGELOG.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
# Enumeration changelog
22

3-
### 3.0.2
3+
### 4.0.0 (2013-08-13)
44

5-
* [Archer](https://github.com/IcecaveStudios/archer) integration
6-
* Implemented changelog
5+
- **[BC BREAK]** `Multiton` method name changes:
6+
- `multitonInstances` -> `members`
7+
- `instanceByKey` -> `memberByKey`
8+
- `instanceBy` -> `memberBy`
9+
- `instanceByPredicate` -> `memberByPredicate`
10+
- `initializeMultiton` -> `initializeMembers`
11+
- `registerMultiton` -> `registerMember`
12+
- `createUndefinedInstanceException` -> `createUndefinedMemberException`
13+
- **[BC BREAK]** `Enumeration` method name changes:
14+
- `instanceByValue` -> `memberByValue`
15+
- **[BC BREAK]** Renamed classes:
16+
- `UndefinedInstanceException` -> `UndefinedMemberException`
17+
- `UndefinedInstanceExceptionInterface` -> `UndefinedMemberExceptionInterface`
18+
- **[NEW]** Case insensitive options for member search methods
19+
- **[NEW]** Defaulting variants of member search methods
20+
- **[MAINTENANCE]** General repository maintenance
21+
22+
### 3.0.2 (2013-03-04)
23+
24+
- **[NEW]** [Archer] integration
25+
- **[NEW]** Implemented changelog
26+
27+
[Archer]: (https://github.com/IcecaveStudios/archer)

README.md

Lines changed: 115 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
*An enumeration implementation for PHP.*
44

5-
[![Build Status]](http://travis-ci.org/eloquent/enumeration)
6-
[![Test Coverage]](http://eloquent-software.com/enumeration/artifacts/tests/coverage/)
5+
[![Build Status]][Latest build]
6+
[![Test Coverage]][Test coverage report]
77

8-
## Installation
8+
## Installation and documentation
99

10-
Available as [Composer](http://getcomposer.org/) package
11-
[eloquent/enumeration](https://packagist.org/packages/eloquent/enumeration).
10+
* Available as [Composer] package [eloquent/enumeration].
11+
* [API documentation] available.
1212

1313
## What is an Enumeration?
1414

@@ -22,32 +22,32 @@ is considered invalid.
2222

2323
## A basic example
2424

25-
Enumeration can be used like [C++ enumerated types](http://www.learncpp.com/cpp-tutorial/45-enumerated-types/).
26-
Here is an example, representing a set of HTTP request methods:
25+
Enumeration can be used like [C++ enumerated types]. Here is an example,
26+
representing a set of HTTP request methods:
2727

2828
```php
2929
use Eloquent\Enumeration\Enumeration;
3030

31-
final class HTTPRequestMethod extends Enumeration
31+
final class HttpRequestMethod extends Enumeration
3232
{
33-
const OPTIONS = 'OPTIONS';
34-
const GET = 'GET';
35-
const HEAD = 'HEAD';
36-
const POST = 'POST';
37-
const PUT = 'PUT';
38-
const DELETE = 'DELETE';
39-
const TRACE = 'TRACE';
40-
const CONNECT = 'CONNECT';
33+
const OPTIONS = 'OPTIONS';
34+
const GET = 'GET';
35+
const HEAD = 'HEAD';
36+
const POST = 'POST';
37+
const PUT = 'PUT';
38+
const DELETE = 'DELETE';
39+
const TRACE = 'TRACE';
40+
const CONNECT = 'CONNECT';
4141
}
4242
```
4343

4444
This class can now be used in a type hint to easily accept any valid HTTP
4545
request method:
4646

4747
```php
48-
function handleHttpRequest(HTTPRequestMethod $method, $url, $body = NULL)
48+
function handleHttpRequest(HttpRequestMethod $method, $url, $body = null)
4949
{
50-
// handle request...
50+
// handle request...
5151
}
5252
```
5353

@@ -56,39 +56,35 @@ function handleHttpRequest(HTTPRequestMethod $method, $url, $body = NULL)
5656
Members are accessed by static method calls, like so:
5757

5858
```php
59-
handleHttpRequest(HTTPRequestMethod::GET(), 'http://example.org/');
60-
handleHttpRequest(HTTPRequestMethod::POST(), 'http://example.org/', 'foo=bar&baz=qux');
59+
handleHttpRequest(HttpRequestMethod::GET(), 'http://example.org/');
60+
handleHttpRequest(HttpRequestMethod::POST(), 'http://example.org/', 'foo=bar&baz=qux');
6161
```
6262

6363
For each member of the enumeration, a single instance of the enumeration class
64-
is instantiated (that is, an instance of *HTTPRequestMethod* in the above
64+
is instantiated (that is, an instance of *HttpRequestMethod* in the above
6565
example). This means that strict comparison (===) can be used to determine
6666
which member has been passed to a function:
6767

6868
```php
69-
function handleHttpRequest(HTTPRequestMethod $method, $url, $body = NULL)
69+
function handleHttpRequest(HttpRequestMethod $method, $url, $body = null)
7070
{
71-
if ($method === HTTPRequestMethod::POST())
72-
{
73-
// handle POST requests...
74-
}
75-
else
76-
{
77-
// handle other requests...
78-
}
71+
if ($method === HttpRequestMethod::POST()) {
72+
// handle POST requests...
73+
} else {
74+
// handle other requests...
75+
}
7976
}
8077
```
8178

8279
## Java-style enumerations
8380

84-
[Java's enum types](http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html)
85-
have slightly more functionality than C++ enumerated types. They can have
86-
additional properties and/or methods, and are really just a specialised kind of
87-
class where there are a fixed set of instances.
81+
[Java's enum types] have slightly more functionality than C++ enumerated types.
82+
They can have additional properties and/or methods, and are really just a
83+
specialised kind of class where there are a fixed set of instances.
8884

89-
This is sometimes called the [Multiton](http://en.wikipedia.org/wiki/Multiton_pattern)
90-
pattern, and in fact, all enumerations in this implementation are Multitons.
91-
The *Enumeration* class simply defines its members based upon class constants.
85+
This is sometimes called the [Multiton] pattern, and in fact, all enumerations
86+
in this implementation are Multitons. The *Enumeration* class simply defines its
87+
members based upon class constants.
9288

9389
Here is an example borrowed from the Java documentation for its enum types. The
9490
following multiton describes all of the planets in our solar system, including
@@ -99,83 +95,84 @@ use Eloquent\Enumeration\Multiton;
9995

10096
final class Planet extends Multiton
10197
{
102-
/**
103-
* Universal gravitational constant
104-
*
105-
* @var float
106-
*/
107-
const G = 6.67300E-11;
108-
109-
/**
110-
* @return float
111-
*/
112-
public function surfaceGravity()
113-
{
114-
return self::G * $this->mass / ($this->radius * $this->radius);
115-
}
116-
117-
/**
118-
* @param float $otherMass
119-
*
120-
* @return float
121-
*/
122-
public function surfaceWeight($otherMass)
123-
{
124-
return $otherMass * $this->surfaceGravity();
125-
}
126-
127-
protected static function initializeMultiton()
128-
{
129-
parent::initializeMultiton();
130-
131-
new static('MERCURY', 3.302e23, 2.4397e6);
132-
new static('VENUS', 4.869e24, 6.0518e6);
133-
new static('EARTH', 5.9742e24, 6.37814e6);
134-
new static('MARS', 6.4191e23, 3.3972e6);
135-
new static('JUPITER', 1.8987e27, 7.1492e7);
136-
new static('SATURN', 5.6851e26, 6.0268e7);
137-
new static('URANUS', 8.6849e25, 2.5559e7);
138-
new static('NEPTUNE', 1.0244e26, 2.4764e7);
139-
// new static('PLUTO', 1.31e22, 1.180e6);
140-
}
141-
142-
/**
143-
* @param string $key
144-
* @param float $mass
145-
* @param float $radius
146-
*/
147-
protected function __construct($key, $mass, $radius)
148-
{
149-
parent::__construct($key);
150-
151-
$this->mass = $mass;
152-
$this->radius = $radius;
153-
}
154-
155-
/**
156-
* @var float
157-
*/
158-
private $mass;
159-
160-
/**
161-
* @var float
162-
*/
163-
private $radius;
98+
/**
99+
* Universal gravitational constant
100+
*
101+
* @var float
102+
*/
103+
const G = 6.67300E-11;
104+
105+
/**
106+
* @return float
107+
*/
108+
public function surfaceGravity()
109+
{
110+
return self::G * $this->mass / ($this->radius * $this->radius);
111+
}
112+
113+
/**
114+
* @param float $otherMass
115+
*
116+
* @return float
117+
*/
118+
public function surfaceWeight($otherMass)
119+
{
120+
return $otherMass * $this->surfaceGravity();
121+
}
122+
123+
protected static function initializeMembers()
124+
{
125+
parent::initializeMembers();
126+
127+
new static('MERCURY', 3.302e23, 2.4397e6);
128+
new static('VENUS', 4.869e24, 6.0518e6);
129+
new static('EARTH', 5.9742e24, 6.37814e6);
130+
new static('MARS', 6.4191e23, 3.3972e6);
131+
new static('JUPITER', 1.8987e27, 7.1492e7);
132+
new static('SATURN', 5.6851e26, 6.0268e7);
133+
new static('URANUS', 8.6849e25, 2.5559e7);
134+
new static('NEPTUNE', 1.0244e26, 2.4764e7);
135+
// new static('PLUTO', 1.31e22, 1.180e6);
136+
}
137+
138+
/**
139+
* @param string $key
140+
* @param float $mass
141+
* @param float $radius
142+
*/
143+
protected function __construct($key, $mass, $radius)
144+
{
145+
parent::__construct($key);
146+
147+
$this->mass = $mass;
148+
$this->radius = $radius;
149+
}
150+
151+
/**
152+
* @var float
153+
*/
154+
private $mass;
155+
156+
/**
157+
* @var float
158+
*/
159+
private $radius;
164160
}
165161
```
166162

167163
The above class can be used to take a known weight on earth (in any unit) and
168164
calculate the weight on all of the planets (in the same unit):
169165

170166
```php
171-
require 'Planet.php';
172-
173167
$earthWeight = 175;
174168
$mass = $earthWeight / Planet::EARTH()->surfaceGravity();
175169

176-
foreach (Planet::multitonInstances() as $planet)
177-
{
178-
echo sprintf('Your weight on %s is %f' . PHP_EOL, $planet, $planet->surfaceWeight($mass));
170+
foreach (Planet::members() as $planet) {
171+
echo sprintf(
172+
'Your weight on %s is %f' . PHP_EOL,
173+
$planet,
174+
$planet->surfaceWeight($mass)
175+
);
179176
}
180177
```
181178

@@ -192,6 +189,17 @@ Your weight on URANUS is 158.424919
192189
Your weight on NEPTUNE is 199.055584
193190
```
194191

195-
<!-- references -->
196-
[Build Status]: https://raw.github.com/eloquent/enumeration/gh-pages/artifacts/images/icecave/regular/build-status.png
197-
[Test Coverage]: https://raw.github.com/eloquent/enumeration/gh-pages/artifacts/images/icecave/regular/coverage.png
192+
<!-- References -->
193+
194+
[API documentation]: http://lqnt.co/enumeration/artifacts/documentation/api/
195+
[C++ enumerated types]: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/
196+
[Composer]: http://getcomposer.org/
197+
[eloquent/enumeration]: https://packagist.org/packages/eloquent/enumeration
198+
[enumeration]: https://github.com/eloquent/enumeration
199+
[Java's enum types]: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
200+
[Multiton]: http://en.wikipedia.org/wiki/Multiton_pattern
201+
202+
[Build Status]: https://api.travis-ci.org/eloquent/enumeration.png?branch=master
203+
[Latest build]: https://travis-ci.org/eloquent/enumeration
204+
[Test coverage report]: https://coveralls.io/r/eloquent/enumeration
205+
[Test Coverage]: https://coveralls.io/repos/eloquent/enumeration/badge.png?branch=master

0 commit comments

Comments
 (0)