Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 4c5db22

Browse files
committed
Merging develop to master in preparation for 3.1.0 release.
2 parents 6217950 + a51b3d5 commit 4c5db22

40 files changed

+621
-97
lines changed

.travis.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ env:
2424
matrix:
2525
fast_finish: true
2626
include:
27-
- php: 5.5
28-
env:
29-
- EXECUTE_CS_CHECK=true
3027
- php: 5.6
3128
env:
32-
- EXECUTE_TEST_COVERALLS=true
29+
- TEST_COVERAGE=true
3330
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
3431
- PATH="$HOME/.local/bin:$PATH"
3532
- php: 7
33+
env:
34+
- CS_CHECK=true
3635
- php: hhvm
3736
allow_failures:
3837
- php: hhvm
@@ -42,21 +41,21 @@ notifications:
4241
email: false
4342

4443
before_install:
45-
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
44+
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
4645
- composer self-update
47-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
46+
- if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
4847

4948
install:
5049
- travis_retry composer install --no-interaction --ignore-platform-reqs
5150

5251
script:
53-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
54-
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
55-
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
52+
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; fi
53+
- if [[ $TEST_COVERAGE != 'true' ]]; then composer test ; fi
54+
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
5655
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi
5756

5857
after_success:
5958
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi
6059

6160
after_script:
62-
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
61+
- if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 3.1.0 - TBD
6+
7+
### Added
8+
9+
- [#63](https://github.com/zendframework/zend-stdlib/pull/63) adds a new
10+
`Zend\Stdlib\ConsoleHelper` class, providing minimal support for writing
11+
output to `STDOUT` and `STDERR`, with optional colorization, when the console
12+
supports that feature.
13+
14+
### Deprecated
15+
16+
- [#38](https://github.com/zendframework/zend-stdlib/pull/38) deprecates
17+
`Zend\Stdlib\JsonSerializable`, as all supported version of PHP now support
18+
it.
19+
20+
### Removed
21+
22+
- Nothing.
23+
24+
### Fixed
25+
26+
- Nothing.
27+
528
## 3.0.2 - TBD
629

730
### Added

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
class for different scopes like:
88

99
- array utilities functions;
10-
- json serializable interfaces;
1110
- general messaging systems;
1211
- string wrappers;
1312
- etc.
1413

1514
---
1615

1716
- File issues at https://github.com/zendframework/zend-stdlib/issues
18-
- Documentation is at http://framework.zend.com/manual/current/en/index.html#zend-stdlib
17+
- Documentation is at https://docs.zendframework.com/zend-stdlib/

composer.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
}
1414
},
1515
"require": {
16-
"php": "^5.5 || ^7.0"
16+
"php": "^5.6 || ^7.0"
1717
},
1818
"require-dev": {
19-
"fabpot/php-cs-fixer": "1.7.*",
19+
"athletic/athletic": "~0.1",
2020
"phpunit/PHPUnit": "~4.0",
21-
"athletic/athletic": "~0.1"
21+
"squizlabs/php_codesniffer": "^2.6.2"
2222
},
2323
"extra": {
2424
"branch-alias": {
@@ -31,5 +31,12 @@
3131
"ZendTest\\Stdlib\\": "test/",
3232
"ZendBench\\Stdlib\\": "benchmark/"
3333
}
34+
},
35+
"scripts": {
36+
"cs-check": "phpcs --colors",
37+
"cs-fix": "phpcbf --colors",
38+
"test": "phpunit --colors=always",
39+
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
40+
"upload-coverage": "coveralls -v"
3441
}
3542
}

doc/book/console-helper.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Console Helper
2+
3+
Writing one-off scripts or vendor binaries for a package is often problematic:
4+
5+
- You need to parse arguments manually.
6+
- You need to send output to the console in a meaningful fashion:
7+
- Using `STDOUT` for meaningful, expected output
8+
- Using `STDERR` for error messages
9+
- Ensuring any line breaks are converted to `PHP_EOL`
10+
- Optionally, using console colors to provide context, which means:
11+
- Detecting whether or not the console supports colors in the first place
12+
- Providing appropriate escape sequences to produce color
13+
14+
`Zend\Stdlib\ConsoleHelper` helps to address the second major bullet point and
15+
all beneath it in a minimal fashion.
16+
17+
## Usage
18+
19+
Typical usage is to instantiate a `ConsoleHelper`, and call one of its methods:
20+
21+
```php
22+
use Zend\Stdlib\ConsoleHelper;
23+
24+
$helper = new ConsoleHelper();
25+
$helper->writeLine('This is output');
26+
```
27+
28+
You can optionally pass a PHP stream resource to the constructor, which will be
29+
used to determine whether or not color support is available:
30+
31+
```php
32+
$helper = new ConsoleHelper($stream);
33+
```
34+
35+
By default, it assumes `STDOUT`, and tests against that.
36+
37+
## Available methods
38+
39+
`ConsoleHelper` provides the following methods.
40+
41+
### colorize
42+
43+
- `colorize(string $string) : string`
44+
45+
`colorize()` accepts a formatted string, and will then apply ANSI color
46+
sequences to them, if color support is detected.
47+
48+
The following sequences are currently supported:
49+
50+
- `<info>...</info>` will apply a green color sequence around the provided text.
51+
- `<error>...</error>` will apply a red color sequence around the provided text.
52+
53+
You may mix multiple sequences within the same stream.
54+
55+
### write
56+
57+
- `write(string $string, bool $colorize = true, resource $stream = STDOUT) : void`
58+
59+
Emits the provided `$string` to the provided `$stream` (which defaults to
60+
`STDOUT` if not provided). Any EOL sequences are convered to `PHP_EOL`. If
61+
`$colorize` is `true`, the string is first passed to `colorize()` as well.
62+
63+
### writeline
64+
65+
- `writeLine(string $string, bool $colorize = true, resource $stream = STDOUT) : void`
66+
67+
Same as `write()`, except it also appends a `PHP_EOL` sequence to the `$string`.
68+
69+
### writeErrorMessage
70+
71+
- `writeErrorMessage(string $message)`
72+
73+
Wraps `$message` in an `<error></error>` sequence, and passes it to
74+
`writeLine()`, using `STDERR` as the `$stream`.
75+
76+
## Example
77+
78+
Below is an example class that accepts an argument list, and determines how and
79+
what to emit.
80+
81+
```php
82+
namespace Foo;
83+
84+
use Zend\Stdlib\ConsoleHelper;
85+
86+
class HelloWorld
87+
{
88+
private $helper;
89+
90+
public function __construct(ConsoleHelper $helper = null)
91+
{
92+
$this->helper = $helper ?: new ConsoleHelper();
93+
}
94+
95+
public function __invoke(array $args)
96+
{
97+
if (! count($args)) {
98+
$this->helper->writeErrorMessage('Missing arguments!');
99+
return;
100+
}
101+
102+
if (count($args) > 1) {
103+
$this->helper->writeErrorMessage('Too many arguments!');
104+
return;
105+
}
106+
107+
$target = array_shift($args);
108+
109+
$this->helper->writeLine(sprintf(
110+
'<info>Hello</info> %s',
111+
$target
112+
));
113+
}
114+
}
115+
```
116+
117+
## When to upgrade
118+
119+
`ConsoleHelper` is deliberately simple, and assumes that your primary need for
120+
console tooling is for output considerations.
121+
122+
If you need to parse complex argument strings, we recommend using
123+
[zend-console](https://docs.zendframework.com/zend-console/)/[zf-console](https://github.com/zfcampus/zf-console)
124+
or [symfony/console](http://symfony.com/doc/current/components/console.html),
125+
as these packages provide those capabilities, as well as far more colorization
126+
and console feature detection facilities.

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ docs_dir: doc/book
22
site_dir: doc/html
33
pages:
44
- index.md
5+
- Reference:
6+
- "Console Helper": console-helper.md
57
- Migration: migration.md
68
site_name: zend-stdlib
79
site_description: Zend\Stdlib

phpcs.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Zend Framework coding standard">
3+
<description>Zend Framework coding standard</description>
4+
5+
<!-- display progress -->
6+
<arg value="p"/>
7+
<arg name="colors"/>
8+
9+
<!-- inherit rules from: -->
10+
<rule ref="PSR2"/>
11+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
12+
<rule ref="Generic.Formatting.SpaceAfterNot"/>
13+
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
14+
<properties>
15+
<property name="ignoreNewlines" value="true"/>
16+
</properties>
17+
</rule>
18+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
19+
<properties>
20+
<property name="ignoreBlankLines" value="false"/>
21+
</properties>
22+
</rule>
23+
24+
<!-- Paths to check -->
25+
<file>src</file>
26+
<file>test</file>
27+
</ruleset>

src/AbstractOptions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
abstract class AbstractOptions implements ParameterObjectInterface
1515
{
16+
// @codingStandardsIgnoreStart
1617
/**
1718
* We use the __ prefix to avoid collisions with properties in
1819
* user-implementations.
1920
*
2021
* @var bool
2122
*/
2223
protected $__strictMode__ = true;
24+
// @codingStandardsIgnoreEnd
2325

2426
/**
2527
* Constructor
@@ -46,7 +48,7 @@ public function setFromArray($options)
4648
$options = $options->toArray();
4749
}
4850

49-
if (!is_array($options) && !$options instanceof Traversable) {
51+
if (! is_array($options) && ! $options instanceof Traversable) {
5052
throw new Exception\InvalidArgumentException(
5153
sprintf(
5254
'Parameter provided to %s must be an %s, %s or %s',

src/ArrayObject.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,16 @@ public function count()
180180
*/
181181
public function exchangeArray($data)
182182
{
183-
if (!is_array($data) && !is_object($data)) {
184-
throw new Exception\InvalidArgumentException('Passed variable is not an array or object, using empty array instead');
183+
if (! is_array($data) && ! is_object($data)) {
184+
throw new Exception\InvalidArgumentException(
185+
'Passed variable is not an array or object, using empty array instead'
186+
);
185187
}
186188

187189
if (is_object($data) && ($data instanceof self || $data instanceof \ArrayObject)) {
188190
$data = $data->getArrayCopy();
189191
}
190-
if (!is_array($data)) {
192+
if (! is_array($data)) {
191193
$data = (array) $data;
192194
}
193195

@@ -290,7 +292,7 @@ public function offsetExists($key)
290292
public function &offsetGet($key)
291293
{
292294
$ret = null;
293-
if (!$this->offsetExists($key)) {
295+
if (! $this->offsetExists($key)) {
294296
return $ret;
295297
}
296298
$ret =& $this->storage[$key];

0 commit comments

Comments
 (0)