1 | <?php namespace Tarsana\Functional; |
||
6 | class Stream { |
||
7 | |||
8 | /** |
||
9 | * The list of predefined operations. |
||
10 | * |
||
11 | * @var array |
||
12 | */ |
||
13 | protected static $operations = null; |
||
14 | |||
15 | /** |
||
16 | * The internal Stream structure described here: src/Internal/_stream.php |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $stream; |
||
21 | |||
22 | /** |
||
23 | * Loads the stream operations from the file src/Internal/_stream_operations.php |
||
24 | * Executed when the first Stream instance is created. |
||
25 | * |
||
26 | * @return void |
||
27 | */ |
||
28 | public static function init() |
||
34 | |||
35 | /** |
||
36 | * Creates a new Stream. |
||
37 | * |
||
38 | * @param mixed $data |
||
39 | * @return Tarsana\Functional\Stream |
||
40 | */ |
||
41 | public static function of($data) |
||
45 | |||
46 | /** |
||
47 | * Adds a new operation to the Stream class. |
||
48 | * |
||
49 | * @param string $name |
||
50 | * @param string $signature |
||
51 | * @param callable $fn |
||
52 | * @return void |
||
53 | */ |
||
54 | public static function operation($name, $signatures, $fn = null) |
||
63 | |||
64 | /** |
||
65 | * Checks if the Stream class has an operation with the given name. |
||
66 | * |
||
67 | * @param string $name |
||
68 | * @return boolean |
||
69 | */ |
||
70 | public static function hasOperation($name) |
||
74 | |||
75 | /** |
||
76 | * Removes one or many operation from the Stream class. |
||
77 | * |
||
78 | * @param string $name |
||
79 | * @return void |
||
80 | */ |
||
81 | public static function removeOperations($name) |
||
88 | |||
89 | /** |
||
90 | * Creates a new Stream with some data. |
||
91 | * |
||
92 | * @param mixed $data |
||
93 | */ |
||
94 | protected function __construct($stream) |
||
98 | |||
99 | /** |
||
100 | * Returns the type of contained data in the stream. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function type() |
||
108 | |||
109 | /** |
||
110 | * Apply all the transformations in the stream and returns the result. |
||
111 | * |
||
112 | * @return mixed |
||
113 | * @throws Tarsana\Functional\Error |
||
114 | */ |
||
115 | public function result() |
||
119 | |||
120 | /** |
||
121 | * Adds a new transformation to the stream. |
||
122 | * |
||
123 | * @param string $name The name of the operation |
||
124 | * @param array $args |
||
125 | * @return Tarsana\Functional\Stream |
||
126 | */ |
||
127 | public function __call($name, $args) |
||
131 | |||
132 | /** |
||
133 | * Returns the string representation of the stream. |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | public function __toString() |
||
141 | |||
142 | } |
||
143 | |||
145 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.