1 | <?php |
||
20 | class SourceTransformingLoader extends PhpStreamFilter |
||
21 | { |
||
22 | /** |
||
23 | * Php filter definition |
||
24 | */ |
||
25 | const PHP_FILTER_READ = 'php://filter/read='; |
||
26 | |||
27 | /** |
||
28 | * Default PHP filter name for registration |
||
29 | */ |
||
30 | const FILTER_IDENTIFIER = 'go.source.transforming.loader'; |
||
31 | |||
32 | /** |
||
33 | * String buffer |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $data = ''; |
||
38 | |||
39 | /** |
||
40 | * List of transformers |
||
41 | * |
||
42 | * @var array|SourceTransformer[] |
||
43 | */ |
||
44 | protected static $transformers = []; |
||
45 | |||
46 | /** |
||
47 | * Identifier of filter |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected static $filterId; |
||
52 | |||
53 | /** |
||
54 | * Register current loader as stream filter in PHP |
||
55 | * |
||
56 | * @param string $filterId Identifier for the filter |
||
57 | * @throws \RuntimeException If registration was failed |
||
58 | */ |
||
59 | public static function register($filterId = self::FILTER_IDENTIFIER) |
||
71 | |||
72 | /** |
||
73 | * Returns the name of registered filter |
||
74 | * |
||
75 | * @throws \RuntimeException if filter was not registered |
||
76 | * @return string |
||
77 | */ |
||
78 | public static function getId() |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function filter($in, $out, &$consumed, $closing) |
||
111 | |||
112 | /** |
||
113 | * Adds a SourceTransformer to be applied by this LoadTimeWeaver. |
||
114 | * |
||
115 | * @param $transformer SourceTransformer Transformer for source code |
||
116 | * |
||
117 | * @return void |
||
118 | */ |
||
119 | public static function addTransformer(SourceTransformer $transformer) |
||
123 | |||
124 | /** |
||
125 | * Transforms source code by passing it through all transformers |
||
126 | * |
||
127 | * @param StreamMetaData|null $metadata Metadata from stream |
||
128 | * @return void|bool Return false if transformation should be stopped |
||
129 | */ |
||
130 | public static function transformCode(StreamMetaData $metadata) |
||
142 | } |
||
143 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: