Skip to content

Commit ea6f627

Browse files
committed
initial commit
0 parents  commit ea6f627

File tree

13 files changed

+668
-0
lines changed

13 files changed

+668
-0
lines changed

.codecov.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: auto
6+
threshold: 1%
7+
patch:
8+
default:
9+
target: auto
10+
threshold: 50%
11+
12+
comment: false
13+
github_checks:
14+
annotations: false

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.yml]
12+
indent_size = 2

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
phpunit.dist.xml export-ignore

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 1,16 * *'
8+
9+
jobs:
10+
tests:
11+
name: PHP ${{ matrix.php }} - ${{ matrix.deps }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
php: [8.0, 8.1]
16+
deps: [hightest]
17+
include:
18+
- php: 8.0
19+
deps: lowest
20+
steps:
21+
- uses: zenstruck/.github@php-test-symfony
22+
with:
23+
php: ${{ matrix.php }}
24+
deps: ${{ matrix.deps }}
25+
26+
code-coverage:
27+
name: Code Coverage
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: zenstruck/.github@php-coverage-codecov
31+
with:
32+
php: 8.1
33+
34+
composer-validate:
35+
uses: zenstruck/.github/.github/workflows/php-composer-validate.yml@main
36+
37+
cs-check:
38+
uses: zenstruck/.github/.github/workflows/php-cs-fixer.yml@main
39+
with:
40+
php: 8.0
41+
42+
sca:
43+
uses: zenstruck/.github/.github/workflows/php-stan.yml@main
44+
with:
45+
php: 8.1

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/composer.lock
2+
/phpunit.xml
3+
/vendor/
4+
/build/
5+
/var/
6+
/.php-cs-fixer.cache
7+
/.phpunit.result.cache

.php-cs-fixer.dist.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in([__DIR__.'/src', __DIR__.'/tests'])
5+
;
6+
$config = new PhpCsFixer\Config();
7+
8+
return $config
9+
->setRules([
10+
'@Symfony' => true,
11+
'@Symfony:risky' => true,
12+
'@DoctrineAnnotation' => true,
13+
'@PHP80Migration' => true,
14+
'@PHP80Migration:risky' => true,
15+
'@PHPUnit75Migration:risky' => true,
16+
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
17+
'multiline_comment_opening_closing' => true,
18+
'array_syntax' => ['syntax' => 'short'],
19+
'ordered_imports' => [
20+
'imports_order' => ['const', 'class', 'function'],
21+
],
22+
'ordered_class_elements' => true,
23+
'native_function_invocation' => ['include' => ['@internal']],
24+
'explicit_indirect_variable' => true,
25+
'explicit_string_variable' => true,
26+
'escape_implicit_backslashes' => true,
27+
'mb_str_functions' => true,
28+
'logical_operators' => true,
29+
'php_unit_method_casing' => ['case' => 'snake_case'],
30+
'php_unit_test_annotation' => ['style' => 'annotation'],
31+
'no_unreachable_default_argument_value' => true,
32+
'declare_strict_types' => false,
33+
'void_return' => false,
34+
'single_trait_insert_per_statement' => false,
35+
'simple_to_complex_string_variable' => true,
36+
'no_superfluous_phpdoc_tags' => [
37+
'allow_mixed' => true,
38+
'allow_unused_params' => true,
39+
'remove_inheritdoc' => true,
40+
],
41+
'phpdoc_to_comment' => false,
42+
'function_declaration' => ['closure_function_spacing' => 'none', 'closure_fn_spacing' => 'none'],
43+
'nullable_type_declaration_for_default_null_value' => true,
44+
'phpdoc_types_order' => ['null_adjustment' => 'none', 'sort_algorithm' => 'none'],
45+
'phpdoc_separation' => ['groups' => [
46+
['test', 'dataProvider'],
47+
['template', 'implements', 'extends'],
48+
['phpstan-type', 'phpstan-import-type'],
49+
['deprecated', 'link', 'see', 'since'],
50+
['author', 'copyright', 'license', 'source'],
51+
['category', 'package', 'subpackage'],
52+
['property', 'property-read', 'property-write'],
53+
]],
54+
])
55+
->setRiskyAllowed(true)
56+
->setFinder($finder)
57+
;

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Kevin Bond
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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# zenstruck/stream
2+
3+
[![CI Status](https://github.com/zenstruck/stream/workflows/CI/badge.svg)](https://github.com/zenstruck/stream/actions?query=workflow%3ACI)
4+
[![codecov](https://codecov.io/gh/zenstruck/stream/branch/1.x/graph/badge.svg?token=3JO1UJPHSE)](https://codecov.io/gh/zenstruck/stream)
5+
6+
Object wrapper for PHP resources.
7+
8+
## Installation
9+
10+
```bash
11+
composer require zenstruck/stream
12+
```
13+
14+
## API
15+
16+
### Create Stream Object
17+
18+
```php
19+
use Zenstruck\Stream;
20+
21+
// wrap
22+
$stream = Stream::wrap($resource);
23+
$stream = Stream::wrap('string');
24+
$stream = Stream::wrap($stream);
25+
26+
// open
27+
$stream = Stream::open('some/file.txt', 'r');
28+
29+
// php://memory
30+
$stream = Stream::inMemory();
31+
32+
// php://output
33+
$stream = Stream::inOutput();
34+
35+
// \tmpfile()
36+
$stream = Stream::tempFile();
37+
```
38+
39+
### Use Stream Object
40+
41+
```php
42+
/** @var \Zenstruck\Stream $stream */
43+
44+
// metadata
45+
$stream->id(); // int - the resource id
46+
$stream->type(); // string - the resource type
47+
$stream->metadata(); // array - the resources metadata
48+
$stream->metadata('wrapper_type'); // mixed - specific resource metadata key
49+
$stream->uri(); // string - shortcut for `$stream->metadata('uri')`
50+
51+
// read
52+
$stream->get(); // resource - the raw, wrapped resource
53+
$stream->contents(); // string - the contents of the resource (auto-rewound)
54+
55+
// write
56+
$stream->write($resource); // self - write another resource to the stream
57+
$stream->write('string'); // self - write a string to the stream
58+
$stream->write($anotherStream); // self - write another \Zenstruck\Stream instance to the stream
59+
60+
// manipulate
61+
$stream->close(); // no-return - close the resource (if open)
62+
$stream->rewind(); // self - rewind the stream
63+
```

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "zenstruck/stream",
3+
"description": "Object wrapper for PHP resources.",
4+
"homepage": "https://github.com/zenstruck/stream",
5+
"type": "library",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Kevin Bond",
10+
"email": "kevinbond@gmail.com"
11+
}
12+
],
13+
"require": {
14+
"php": ">=8.0"
15+
},
16+
"require-dev": {
17+
"phpstan/phpstan": "^1.4",
18+
"phpunit/phpunit": "^9.5.0",
19+
"symfony/phpunit-bridge": "^6.1",
20+
"symfony/var-dumper": "^5.4|^6.0"
21+
},
22+
"config": {
23+
"preferred-install": "dist",
24+
"sort-packages": true
25+
},
26+
"autoload": {
27+
"psr-4": { "Zenstruck\\": ["src/"] }
28+
},
29+
"autoload-dev": {
30+
"psr-4": { "Zenstruck\\Tests\\": ["tests/"] }
31+
}
32+
}

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
treatPhpDocTypesAsCertain: false
6+

0 commit comments

Comments
 (0)