├── .gitignore
├── Home.php
├── LICENSE
├── Python
└── include
│ ├── Snippet file here
│ └── library
│ ├── __pycache__
│ └── phpy.cpython-39.pyc
│ └── phpy.py
├── README.md
├── composer.json
├── composer.lock
├── core
├── App.php
├── Python.php
├── Snippet.php
└── live.php
├── favicon.ico
└── vendor
├── autoload.php
└── composer
├── ClassLoader.php
├── InstalledVersions.php
├── LICENSE
├── autoload_classmap.php
├── autoload_namespaces.php
├── autoload_psr4.php
├── autoload_real.php
├── autoload_static.php
├── installed.json
└── installed.php
/.gitignore:
--------------------------------------------------------------------------------
1 | Git.py
--------------------------------------------------------------------------------
/Home.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | phpy
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | EXAMPLE CODES
17 |
18 |
19 | PHP
20 |
21 |
22 | PYTHON
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Raeen Ahani Azari
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.
22 |
--------------------------------------------------------------------------------
/Python/include/Snippet file here:
--------------------------------------------------------------------------------
1 | Snippet file here
2 |
3 | Don't delete Snippet.py
--------------------------------------------------------------------------------
/Python/include/library/__pycache__/phpy.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Raeen123/phpy/b30b47ce112b8748590571c7735743901cdb37e7/Python/include/library/__pycache__/phpy.cpython-39.pyc
--------------------------------------------------------------------------------
/Python/include/library/phpy.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import json
3 | import base64
4 | import numpy as np
5 | import cv2
6 |
7 |
8 | def get_data(index_args):
9 | json_php_get = sys.argv[index_args]
10 | php_get = json_php_get.replace(" ", '"')
11 | try:
12 | jsons = json.loads(php_get)
13 | return jsons
14 | except:
15 | print('error from get data')
16 |
17 |
18 | def push_data(data):
19 | print(json.dumps(data))
20 |
21 |
22 | def push_img(img, type):
23 | type_res = "."+type
24 | _, im_arr = cv2.imencode(type_res, img)
25 | im_bytes = im_arr.tobytes()
26 | im_b64 = base64.b64encode(im_bytes)
27 | return(im_b64)
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | **phpy is library for php**
4 |
5 | You can use python in php with it
6 |
7 | [](//packagist.org/packages/raeen/phpy) [](//packagist.org/packages/raeen/phpy) [](//packagist.org/packages/raeen/phpy) [](//packagist.org/packages/raeen/phpy)[](//packagist.org/packages/raeen/phpy) [](//packagist.org/packages/raeen/phpy)
8 |
9 | ***
10 | ## Features
11 | - Show all output from python file
12 | - Show last line output from python
13 | - Send data to python file
14 | - Get data from python file
15 | - show image in php from python
16 | - path Genrate
17 | - write python line code
18 | - mange python line code
19 | - write python part
20 | - require python part
21 | ***
22 |
23 | **Install**
24 | ```batch
25 | git clone https://github.com/Raeen123/phpy
26 | ```
27 | ```batch
28 | composer require raeen/phpy
29 | ```
30 |
31 | ***
32 |
33 | **Prerequisites**
34 |
35 | This is mine config:
36 | ```
37 | php = 8.0.1 (Your php version must be at least 7.4 )
38 | python = 3.9.1
39 | numpy = 1.19.3
40 | python-opencv = 4.4.0.46
41 | ```
42 |
43 | ***
44 |
45 | **Python**
46 |
47 | You must if you don't add python in your path environment , add yor python path in ``` core/Python.php ``` in ``` const python_path ```
48 |
49 | We use these libraries for create phpy.py:
50 |
51 | ```python
52 | import sys
53 | import json
54 | import base64
55 | import numpy as np
56 | import cv2
57 | ```
58 |
59 | Import phpy.py file in Python/include/library/php.py
60 |
61 | ***
62 | **Get Data from php**
63 |
64 | Get datas to python file
65 | For Get data you must
66 |
67 | ```python
68 | phpy.get_data( Number Of Send data )
69 | ```
70 |
71 |
72 | For return data you must use print function
73 | ***
74 |
75 | **Push data from python**
76 | ```python
77 | phpy.push_data(data)
78 | ```
79 | It's just
80 | ```python
81 | json.dumps(data)
82 | ```
83 | ***
84 | **Push image from python**
85 |
86 | It function for pushing data from python to php
87 |
88 | Example for reading image
89 | ```python
90 | cv2.imread()
91 | ```
92 | ```python
93 | videoCaptureObject = cv2.VideoCapture(0)
94 | ret, frame = videoCaptureObject.read()
95 | ```
96 |
97 | Pushing image
98 | ```python
99 | phpy.push_image(img,type)
100 | ```
101 | ***
102 | **Send data from php**
103 |
104 | Create and Send data from php to python
105 |
106 | You can send infinite data
107 |
108 | ```php
109 | require_once "../vendor/autoload.php";
110 |
111 | use app\core\App;
112 |
113 | $app = new App();
114 | $python = $app->python;
115 |
116 | $data1 = [
117 | 'name' => 'raeen',
118 | 'library' => 'phpy'
119 | ];
120 | $data2 = "test";
121 | $output = $python->set("../Python/test2.py")->send($data1, $data2)->gen();
122 | ```
123 | live output example:
124 |
125 |
126 | ```php
127 | $site = "google.com";
128 | $python->set('../Python/test6.py')->send($data)->live()->gen();
129 | ```
130 | ***
131 | **Show result**
132 |
133 | ```php
134 | $output = $python->set(path)->send(datas..)->gen()
135 | ```
136 |
137 |
138 | ***
139 | **Show Img**
140 |
141 | You can use this function to genrate what's return from phpy.push_img()
142 | ```php
143 | $app->img($output,$type,$show,$style)
144 | ```
145 | **$type must be same type in php.push_img()**
146 |
147 | If $show is true , show image in img tag
148 |
149 | Also you can set style for this
150 |
151 | Example
152 | ```php
153 | $app->img($output,$type,true,
154 | [
155 | 'border' => '1px solid red'
156 | ])
157 | ```
158 | ***
159 | **Path**
160 |
161 | For example , I have image file in this diractory but python file in Python/**.py and I want to send path to it . for this in must to send this path ../my-img Or use this functiuon for send path file or directory
162 |
163 | ```php
164 | $app->path(__Dir__,path)
165 | ```
166 |
167 | ***
168 | **Ini**
169 |
170 | If you have loop in php file it's very good to add this function in top of file
171 |
172 | ```php
173 | $app->ini()
174 | ```
175 | ***
176 |
177 | **Snippet**
178 |
179 | **One Line**
180 |
181 | If you want to run a python line , you should use this function
182 |
183 | ```php
184 | $Snippet->set($code,function(){
185 | // controller
186 | })->gen();
187 | ```
188 |
189 | For control varable , you should it's name in ``` |&name| ```
190 |
191 | For fill varable you should ```return array``` , it must be in order
192 |
193 | You must use ```"``` in python code and use ```;``` in the end of each line
194 | ```php
195 | $Snippet = $app->snippet;
196 | $Snippet->set("print(f'hello world {|&data|*7*|&test|}'); print('--Hello')",
197 | function ($data,$test) {
198 | $data = 2;
199 | $test = 9;
200 | $data2 = $data*5;
201 | return [$data2 , $test];
202 | })->gen();
203 |
204 | ```
205 | **Lines**
206 |
207 | **start**
208 | Before start writing codes you should use this
209 |
210 | ```php
211 | $Snippet->start(name);
212 | ```
213 |
214 | For write your codes , you should use this
215 |
216 | ```php
217 |
218 | $Snippet->line(code)
219 | .
220 | .
221 | .
222 |
223 | ```
224 |
225 | For end of lines
226 |
227 | ```php
228 | $Snippet->end(name,save_last)
229 | ```
230 |
231 | *name in start function must be same this name*
232 |
233 | For get output anywhere you should use this
234 |
235 | ```php
236 | $Snippet->select(name)->gen()
237 | ```
238 |
239 |
240 | **Example , index.php :**
241 |
242 | ```php
243 | $Snippet->start("test");
244 | $Snippet->line("a = 'Hello world'");
245 | $Snippet->line("print(a)");
246 | $Snippet->end("test");
247 | $Snippet->select("test")->gen();
248 | ```
249 |
250 | ```output
251 | Output : Hello world
252 | ```
253 |
254 | **You can use this code in another file**
255 |
256 | ```php
257 |
258 | $Snippet->select("test")->gen();
259 |
260 | ```
261 |
262 | ```output
263 | Output : Hello world
264 | ```
265 | ***
266 |
267 | **Live Output**
268 | Any where (Snippet and Python class) you can use this so easy
269 |
270 | just before use ```gen()``` use ```live()``` then use ```gen(/* you can write function here to control output */)
271 | ```php
272 | $python->set("../Python/test6.py")->send($site)->live()->gen(
273 | function ($res) {
274 | return "$res
";
275 | }
276 | );
277 | ```
278 | you can also set time without each reading ouput (defult is 1)
279 | ```php
280 | $python->set("../Python/test6.py")->send($site)->live()->ini(3)->gen(
281 | function ($res) {
282 | return "$res
";
283 | }
284 | );
285 | ```
286 | ```php
287 | $Snippet->set(
288 | "import subprocess as sub; sub.call('ping |&site|') ",function($site){ $site = "google.com"; return [$site];}
289 | )->live()->ini(3)->gen();
290 |
291 | ```
292 |
293 | ```php
294 | $Snippet->select('snippet-test8')->live()->gen(function($res){ return "$res
";});
295 | ```
296 | **License**
297 |
298 | MIT License
299 |
300 | Copyright (c) 2021 Raeen Ahani Azari
301 |
302 | Permission is hereby granted, free of charge, to any person obtaining a copy
303 | of this software and associated documentation files (the "Software"), to deal
304 | in the Software without restriction, including without limitation the rights
305 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
306 | copies of the Software, and to permit persons to whom the Software is
307 | furnished to do so, subject to the following conditions:
308 |
309 | The above copyright notice and this permission notice shall be included in all
310 | copies or substantial portions of the Software.
311 |
312 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
313 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
314 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
315 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
316 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
317 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
318 | SOFTWARE.
319 | ***
320 |
321 | **Example**
322 |
323 | There are examples in [phpy-examples](https://github.com/Raeen123/phpy-examples)
324 | ***
325 | **BY RAEEN AHANI AZARI**
326 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "raeen/phpy",
3 | "type": "library",
4 | "description" : "Use python in php very easy",
5 | "license" : "MIT",
6 | "authors": [
7 | {
8 | "name": "Raeen",
9 | "email": "raeen.ahniazari@gmail.com"
10 | }
11 | ],
12 | "minimum-stability" : "dev",
13 | "require": {
14 | "php" : ">=7.4"
15 | },
16 | "autoload": {
17 | "psr-4": {
18 | "app\\": "./"
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "11571cbb8b169db90d098aca780b6530",
8 | "packages": [],
9 | "packages-dev": [],
10 | "aliases": [],
11 | "minimum-stability": "stable",
12 | "stability-flags": [],
13 | "prefer-stable": false,
14 | "prefer-lowest": false,
15 | "platform": [],
16 | "platform-dev": [],
17 | "plugin-api-version": "2.0.0"
18 | }
19 |
--------------------------------------------------------------------------------
/core/App.php:
--------------------------------------------------------------------------------
1 | python = new Python();
13 | $this->snippet = new Snippet();
14 | $this->live = new live();
15 | }
16 | public function img(string $output, string $type, bool $show = false, array $style = null)
17 | {
18 | $styles = null;
19 | if (!is_null($style) && $show) {
20 | foreach ($style as $key => $value) {
21 | $styles .= "$key : $value;";
22 | }
23 | }
24 | $res = substr($output, 2, -1);
25 | if ($show) {
26 | echo "
";
27 | }
28 | return "data:image/" . $type . ";base64," . $res;
29 | }
30 | public function path($dir, $path)
31 | {
32 | $local_path = explode('/', $path);
33 | $dir_path = explode("\\", $dir);
34 |
35 | $back = null;
36 | if (isset(array_count_values($local_path)['..'])) {
37 | $back = array_count_values($local_path)['..'];
38 | } else {
39 | $back = 0;
40 | }
41 |
42 | $result_local = null;
43 | $result_dir = null;
44 | foreach ($local_path as $key => $value) {
45 | if ($local_path[$key] < $back) {
46 | continue;
47 | }
48 | if (!is_dir($path)) {
49 | if ($key + 1 == count($local_path)) {
50 | $result_local .= $value;
51 | } else {
52 | $result_local .= $value . "/";
53 | }
54 | } else {
55 | $result_local .= $value . "/";
56 | }
57 | }
58 | foreach ($dir_path as $key => $value) {
59 | if ($key < (count($dir_path) - $back)) {
60 | $result_dir .= $value . "/";
61 | }
62 | }
63 | return $result_dir . $result_local;
64 | }
65 | public function ini()
66 | {
67 | @ini_set("output_buffering", "Off");
68 | @ini_set('implicit_flush', 1);
69 | @ini_set('zlib.output_compression', 0);
70 | @ini_set('max_execution_time', 1200);
71 | header('Content-type: text/html; charset=utf-8');
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/core/Python.php:
--------------------------------------------------------------------------------
1 | &1";
16 | $this->command = $command;
17 | return $this;
18 | }
19 | public function send(...$datas)
20 | {
21 | $resultargs = null;
22 | foreach ($datas as $send) {
23 | $resultargs .= escapeshellarg(json_encode($send)) . " ";
24 | }
25 | $this->args = $resultargs;
26 | return $this;
27 | }
28 | protected function command_config()
29 | {
30 | return $this->command." ".$this->args;
31 | }
32 | public function gen()
33 | {
34 | return shell_exec($this->command_config());
35 | }
36 | public function live()
37 | {
38 | $this->live = new live($this->command_config());
39 | return $this->live;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/core/Snippet.php:
--------------------------------------------------------------------------------
1 | command);
14 | }
15 | public function path($name)
16 | {
17 | return str_replace('core\\', '', __DIR__ . '\Python\include/' . $name . '.py');
18 | }
19 | public function start(string $name)
20 | {
21 | ob_start();
22 | }
23 | public function set($code, $fun = null)
24 | {
25 | $code = (string) $code;
26 | if (is_object($fun)) {
27 | $prams = explode('|', $code);
28 | $all_prams = array();
29 | for ($i = 0; $i < count($prams); $i++) {
30 | if ($prams[$i][0] == '&') {
31 | array_push($all_prams, $prams[$i]);
32 | }
33 | }
34 | $code_res = call_user_func_array($fun, $all_prams);
35 | if (!is_array($code_res)) {
36 | die("You must return array");
37 | }
38 | $o = 0;
39 | foreach ($prams as $key => $value) {
40 | if ($value[0] == '&') {
41 | $prams[$key] = $code_res[$o];
42 | $o++;
43 | }
44 | }
45 | $code_result = implode("", $prams);
46 | } else {
47 | $code_result = $code;
48 | }
49 | $this->command = Python::python_path . ' -c "' . $code_result . '"';
50 | return $this;
51 | }
52 | public function end(string $name, bool $save_last = false)
53 | {
54 | $codes = ob_get_clean();
55 | $path = $this->path($name);
56 | $metod = ($save_last) ? 'a' : 'w';
57 | $file = fopen($path, $metod);
58 | if (!$save_last) {
59 | if (file_get_contents($path) != $codes) {
60 | fwrite($file, (string) $codes);
61 | }
62 | fclose($file);
63 | } else {
64 | $file = fopen($path, $metod);
65 | fwrite($file, (string) $codes);
66 | fclose($file);
67 | }
68 | }
69 | public function line($line)
70 | {
71 | echo (string) $line . " \x0D";
72 | }
73 | public function select($name)
74 | {
75 | $this->command = Python::python_path . " " . $this->path($name) . " 2>&1";
76 | return $this;
77 | }
78 | public function live()
79 | {
80 | $this->live = new live($this->command);
81 | return $this->live;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/core/live.php:
--------------------------------------------------------------------------------
1 | commad = $commad;
13 | return $this;
14 | }
15 | public function ini($time = null)
16 | {
17 | if (!is_null($time) && 0 < $time) {
18 | $this->time = $time;
19 | }
20 | return $this;
21 | }
22 | public function gen(object $controller = null)
23 | {
24 | $pid = popen($this->commad, "r");
25 | while (!feof($pid)) {
26 | $res = fgets($pid);
27 |
28 | if (!is_null($controller)) {
29 | $res = call_user_func($controller, $res);
30 | }
31 |
32 | echo $res;
33 |
34 |
35 | flush();
36 | ob_flush();
37 | sleep($this->time);
38 | }
39 | pclose($pid);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Raeen123/phpy/b30b47ce112b8748590571c7735743901cdb37e7/favicon.ico
--------------------------------------------------------------------------------
/vendor/autoload.php:
--------------------------------------------------------------------------------
1 |
7 | * Jordi Boggiano
8 | *
9 | * For the full copyright and license information, please view the LICENSE
10 | * file that was distributed with this source code.
11 | */
12 |
13 | namespace Composer\Autoload;
14 |
15 | /**
16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
17 | *
18 | * $loader = new \Composer\Autoload\ClassLoader();
19 | *
20 | * // register classes with namespaces
21 | * $loader->add('Symfony\Component', __DIR__.'/component');
22 | * $loader->add('Symfony', __DIR__.'/framework');
23 | *
24 | * // activate the autoloader
25 | * $loader->register();
26 | *
27 | * // to enable searching the include path (eg. for PEAR packages)
28 | * $loader->setUseIncludePath(true);
29 | *
30 | * In this example, if you try to use a class in the Symfony\Component
31 | * namespace or one of its children (Symfony\Component\Console for instance),
32 | * the autoloader will first look for the class under the component/
33 | * directory, and it will then fallback to the framework/ directory if not
34 | * found before giving up.
35 | *
36 | * This class is loosely based on the Symfony UniversalClassLoader.
37 | *
38 | * @author Fabien Potencier
39 | * @author Jordi Boggiano
40 | * @see https://www.php-fig.org/psr/psr-0/
41 | * @see https://www.php-fig.org/psr/psr-4/
42 | */
43 | class ClassLoader
44 | {
45 | // PSR-4
46 | private $prefixLengthsPsr4 = array();
47 | private $prefixDirsPsr4 = array();
48 | private $fallbackDirsPsr4 = array();
49 |
50 | // PSR-0
51 | private $prefixesPsr0 = array();
52 | private $fallbackDirsPsr0 = array();
53 |
54 | private $useIncludePath = false;
55 | private $classMap = array();
56 | private $classMapAuthoritative = false;
57 | private $missingClasses = array();
58 | private $apcuPrefix;
59 |
60 | public function getPrefixes()
61 | {
62 | if (!empty($this->prefixesPsr0)) {
63 | return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
64 | }
65 |
66 | return array();
67 | }
68 |
69 | public function getPrefixesPsr4()
70 | {
71 | return $this->prefixDirsPsr4;
72 | }
73 |
74 | public function getFallbackDirs()
75 | {
76 | return $this->fallbackDirsPsr0;
77 | }
78 |
79 | public function getFallbackDirsPsr4()
80 | {
81 | return $this->fallbackDirsPsr4;
82 | }
83 |
84 | public function getClassMap()
85 | {
86 | return $this->classMap;
87 | }
88 |
89 | /**
90 | * @param array $classMap Class to filename map
91 | */
92 | public function addClassMap(array $classMap)
93 | {
94 | if ($this->classMap) {
95 | $this->classMap = array_merge($this->classMap, $classMap);
96 | } else {
97 | $this->classMap = $classMap;
98 | }
99 | }
100 |
101 | /**
102 | * Registers a set of PSR-0 directories for a given prefix, either
103 | * appending or prepending to the ones previously set for this prefix.
104 | *
105 | * @param string $prefix The prefix
106 | * @param array|string $paths The PSR-0 root directories
107 | * @param bool $prepend Whether to prepend the directories
108 | */
109 | public function add($prefix, $paths, $prepend = false)
110 | {
111 | if (!$prefix) {
112 | if ($prepend) {
113 | $this->fallbackDirsPsr0 = array_merge(
114 | (array) $paths,
115 | $this->fallbackDirsPsr0
116 | );
117 | } else {
118 | $this->fallbackDirsPsr0 = array_merge(
119 | $this->fallbackDirsPsr0,
120 | (array) $paths
121 | );
122 | }
123 |
124 | return;
125 | }
126 |
127 | $first = $prefix[0];
128 | if (!isset($this->prefixesPsr0[$first][$prefix])) {
129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths;
130 |
131 | return;
132 | }
133 | if ($prepend) {
134 | $this->prefixesPsr0[$first][$prefix] = array_merge(
135 | (array) $paths,
136 | $this->prefixesPsr0[$first][$prefix]
137 | );
138 | } else {
139 | $this->prefixesPsr0[$first][$prefix] = array_merge(
140 | $this->prefixesPsr0[$first][$prefix],
141 | (array) $paths
142 | );
143 | }
144 | }
145 |
146 | /**
147 | * Registers a set of PSR-4 directories for a given namespace, either
148 | * appending or prepending to the ones previously set for this namespace.
149 | *
150 | * @param string $prefix The prefix/namespace, with trailing '\\'
151 | * @param array|string $paths The PSR-4 base directories
152 | * @param bool $prepend Whether to prepend the directories
153 | *
154 | * @throws \InvalidArgumentException
155 | */
156 | public function addPsr4($prefix, $paths, $prepend = false)
157 | {
158 | if (!$prefix) {
159 | // Register directories for the root namespace.
160 | if ($prepend) {
161 | $this->fallbackDirsPsr4 = array_merge(
162 | (array) $paths,
163 | $this->fallbackDirsPsr4
164 | );
165 | } else {
166 | $this->fallbackDirsPsr4 = array_merge(
167 | $this->fallbackDirsPsr4,
168 | (array) $paths
169 | );
170 | }
171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
172 | // Register directories for a new namespace.
173 | $length = strlen($prefix);
174 | if ('\\' !== $prefix[$length - 1]) {
175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
176 | }
177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
178 | $this->prefixDirsPsr4[$prefix] = (array) $paths;
179 | } elseif ($prepend) {
180 | // Prepend directories for an already registered namespace.
181 | $this->prefixDirsPsr4[$prefix] = array_merge(
182 | (array) $paths,
183 | $this->prefixDirsPsr4[$prefix]
184 | );
185 | } else {
186 | // Append directories for an already registered namespace.
187 | $this->prefixDirsPsr4[$prefix] = array_merge(
188 | $this->prefixDirsPsr4[$prefix],
189 | (array) $paths
190 | );
191 | }
192 | }
193 |
194 | /**
195 | * Registers a set of PSR-0 directories for a given prefix,
196 | * replacing any others previously set for this prefix.
197 | *
198 | * @param string $prefix The prefix
199 | * @param array|string $paths The PSR-0 base directories
200 | */
201 | public function set($prefix, $paths)
202 | {
203 | if (!$prefix) {
204 | $this->fallbackDirsPsr0 = (array) $paths;
205 | } else {
206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
207 | }
208 | }
209 |
210 | /**
211 | * Registers a set of PSR-4 directories for a given namespace,
212 | * replacing any others previously set for this namespace.
213 | *
214 | * @param string $prefix The prefix/namespace, with trailing '\\'
215 | * @param array|string $paths The PSR-4 base directories
216 | *
217 | * @throws \InvalidArgumentException
218 | */
219 | public function setPsr4($prefix, $paths)
220 | {
221 | if (!$prefix) {
222 | $this->fallbackDirsPsr4 = (array) $paths;
223 | } else {
224 | $length = strlen($prefix);
225 | if ('\\' !== $prefix[$length - 1]) {
226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
227 | }
228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
229 | $this->prefixDirsPsr4[$prefix] = (array) $paths;
230 | }
231 | }
232 |
233 | /**
234 | * Turns on searching the include path for class files.
235 | *
236 | * @param bool $useIncludePath
237 | */
238 | public function setUseIncludePath($useIncludePath)
239 | {
240 | $this->useIncludePath = $useIncludePath;
241 | }
242 |
243 | /**
244 | * Can be used to check if the autoloader uses the include path to check
245 | * for classes.
246 | *
247 | * @return bool
248 | */
249 | public function getUseIncludePath()
250 | {
251 | return $this->useIncludePath;
252 | }
253 |
254 | /**
255 | * Turns off searching the prefix and fallback directories for classes
256 | * that have not been registered with the class map.
257 | *
258 | * @param bool $classMapAuthoritative
259 | */
260 | public function setClassMapAuthoritative($classMapAuthoritative)
261 | {
262 | $this->classMapAuthoritative = $classMapAuthoritative;
263 | }
264 |
265 | /**
266 | * Should class lookup fail if not found in the current class map?
267 | *
268 | * @return bool
269 | */
270 | public function isClassMapAuthoritative()
271 | {
272 | return $this->classMapAuthoritative;
273 | }
274 |
275 | /**
276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
277 | *
278 | * @param string|null $apcuPrefix
279 | */
280 | public function setApcuPrefix($apcuPrefix)
281 | {
282 | $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
283 | }
284 |
285 | /**
286 | * The APCu prefix in use, or null if APCu caching is not enabled.
287 | *
288 | * @return string|null
289 | */
290 | public function getApcuPrefix()
291 | {
292 | return $this->apcuPrefix;
293 | }
294 |
295 | /**
296 | * Registers this instance as an autoloader.
297 | *
298 | * @param bool $prepend Whether to prepend the autoloader or not
299 | */
300 | public function register($prepend = false)
301 | {
302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend);
303 | }
304 |
305 | /**
306 | * Unregisters this instance as an autoloader.
307 | */
308 | public function unregister()
309 | {
310 | spl_autoload_unregister(array($this, 'loadClass'));
311 | }
312 |
313 | /**
314 | * Loads the given class or interface.
315 | *
316 | * @param string $class The name of the class
317 | * @return bool|null True if loaded, null otherwise
318 | */
319 | public function loadClass($class)
320 | {
321 | if ($file = $this->findFile($class)) {
322 | includeFile($file);
323 |
324 | return true;
325 | }
326 | }
327 |
328 | /**
329 | * Finds the path to the file where the class is defined.
330 | *
331 | * @param string $class The name of the class
332 | *
333 | * @return string|false The path if found, false otherwise
334 | */
335 | public function findFile($class)
336 | {
337 | // class map lookup
338 | if (isset($this->classMap[$class])) {
339 | return $this->classMap[$class];
340 | }
341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
342 | return false;
343 | }
344 | if (null !== $this->apcuPrefix) {
345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit);
346 | if ($hit) {
347 | return $file;
348 | }
349 | }
350 |
351 | $file = $this->findFileWithExtension($class, '.php');
352 |
353 | // Search for Hack files if we are running on HHVM
354 | if (false === $file && defined('HHVM_VERSION')) {
355 | $file = $this->findFileWithExtension($class, '.hh');
356 | }
357 |
358 | if (null !== $this->apcuPrefix) {
359 | apcu_add($this->apcuPrefix.$class, $file);
360 | }
361 |
362 | if (false === $file) {
363 | // Remember that this class does not exist.
364 | $this->missingClasses[$class] = true;
365 | }
366 |
367 | return $file;
368 | }
369 |
370 | private function findFileWithExtension($class, $ext)
371 | {
372 | // PSR-4 lookup
373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
374 |
375 | $first = $class[0];
376 | if (isset($this->prefixLengthsPsr4[$first])) {
377 | $subPath = $class;
378 | while (false !== $lastPos = strrpos($subPath, '\\')) {
379 | $subPath = substr($subPath, 0, $lastPos);
380 | $search = $subPath . '\\';
381 | if (isset($this->prefixDirsPsr4[$search])) {
382 | $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
383 | foreach ($this->prefixDirsPsr4[$search] as $dir) {
384 | if (file_exists($file = $dir . $pathEnd)) {
385 | return $file;
386 | }
387 | }
388 | }
389 | }
390 | }
391 |
392 | // PSR-4 fallback dirs
393 | foreach ($this->fallbackDirsPsr4 as $dir) {
394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
395 | return $file;
396 | }
397 | }
398 |
399 | // PSR-0 lookup
400 | if (false !== $pos = strrpos($class, '\\')) {
401 | // namespaced class name
402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
404 | } else {
405 | // PEAR-like class name
406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
407 | }
408 |
409 | if (isset($this->prefixesPsr0[$first])) {
410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
411 | if (0 === strpos($class, $prefix)) {
412 | foreach ($dirs as $dir) {
413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
414 | return $file;
415 | }
416 | }
417 | }
418 | }
419 | }
420 |
421 | // PSR-0 fallback dirs
422 | foreach ($this->fallbackDirsPsr0 as $dir) {
423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
424 | return $file;
425 | }
426 | }
427 |
428 | // PSR-0 include paths.
429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
430 | return $file;
431 | }
432 |
433 | return false;
434 | }
435 | }
436 |
437 | /**
438 | * Scope isolated include.
439 | *
440 | * Prevents access to $this/self from included files.
441 | */
442 | function includeFile($file)
443 | {
444 | include $file;
445 | }
446 |
--------------------------------------------------------------------------------
/vendor/composer/InstalledVersions.php:
--------------------------------------------------------------------------------
1 |
26 | array (
27 | 'pretty_version' => '1.0.0+no-version-set',
28 | 'version' => '1.0.0.0',
29 | 'aliases' =>
30 | array (
31 | ),
32 | 'reference' => NULL,
33 | 'name' => 'raeen/phpy',
34 | ),
35 | 'versions' =>
36 | array (
37 | 'raeen/phpy' =>
38 | array (
39 | 'pretty_version' => '1.0.0+no-version-set',
40 | 'version' => '1.0.0.0',
41 | 'aliases' =>
42 | array (
43 | ),
44 | 'reference' => NULL,
45 | ),
46 | ),
47 | );
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | public static function getInstalledPackages()
56 | {
57 | return array_keys(self::$installed['versions']);
58 | }
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | public static function isInstalled($packageName)
69 | {
70 | return isset(self::$installed['versions'][$packageName]);
71 | }
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | public static function satisfies(VersionParser $parser, $packageName, $constraint)
87 | {
88 | $constraint = $parser->parseConstraints($constraint);
89 | $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
90 |
91 | return $provided->matches($constraint);
92 | }
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 | public static function getVersionRanges($packageName)
104 | {
105 | if (!isset(self::$installed['versions'][$packageName])) {
106 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
107 | }
108 |
109 | $ranges = array();
110 | if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
111 | $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
112 | }
113 | if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
114 | $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
115 | }
116 | if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
117 | $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
118 | }
119 | if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
120 | $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
121 | }
122 |
123 | return implode(' || ', $ranges);
124 | }
125 |
126 |
127 |
128 |
129 |
130 | public static function getVersion($packageName)
131 | {
132 | if (!isset(self::$installed['versions'][$packageName])) {
133 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
134 | }
135 |
136 | if (!isset(self::$installed['versions'][$packageName]['version'])) {
137 | return null;
138 | }
139 |
140 | return self::$installed['versions'][$packageName]['version'];
141 | }
142 |
143 |
144 |
145 |
146 |
147 | public static function getPrettyVersion($packageName)
148 | {
149 | if (!isset(self::$installed['versions'][$packageName])) {
150 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
151 | }
152 |
153 | if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
154 | return null;
155 | }
156 |
157 | return self::$installed['versions'][$packageName]['pretty_version'];
158 | }
159 |
160 |
161 |
162 |
163 |
164 | public static function getReference($packageName)
165 | {
166 | if (!isset(self::$installed['versions'][$packageName])) {
167 | throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
168 | }
169 |
170 | if (!isset(self::$installed['versions'][$packageName]['reference'])) {
171 | return null;
172 | }
173 |
174 | return self::$installed['versions'][$packageName]['reference'];
175 | }
176 |
177 |
178 |
179 |
180 |
181 | public static function getRootPackage()
182 | {
183 | return self::$installed['root'];
184 | }
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 | public static function getRawData()
193 | {
194 | return self::$installed;
195 | }
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 | public static function reload($data)
216 | {
217 | self::$installed = $data;
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/vendor/composer/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) Nils Adermann, Jordi Boggiano
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is furnished
9 | to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 |
22 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_classmap.php:
--------------------------------------------------------------------------------
1 | $vendorDir . '/composer/InstalledVersions.php',
10 | );
11 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_namespaces.php:
--------------------------------------------------------------------------------
1 | array($baseDir . '/'),
10 | );
11 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_real.php:
--------------------------------------------------------------------------------
1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30 | if ($useStaticLoader) {
31 | require __DIR__ . '/autoload_static.php';
32 |
33 | call_user_func(\Composer\Autoload\ComposerStaticInitd4e167bbb381ca3cc629eccfb7622e38::getInitializer($loader));
34 | } else {
35 | $map = require __DIR__ . '/autoload_namespaces.php';
36 | foreach ($map as $namespace => $path) {
37 | $loader->set($namespace, $path);
38 | }
39 |
40 | $map = require __DIR__ . '/autoload_psr4.php';
41 | foreach ($map as $namespace => $path) {
42 | $loader->setPsr4($namespace, $path);
43 | }
44 |
45 | $classMap = require __DIR__ . '/autoload_classmap.php';
46 | if ($classMap) {
47 | $loader->addClassMap($classMap);
48 | }
49 | }
50 |
51 | $loader->register(true);
52 |
53 | return $loader;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_static.php:
--------------------------------------------------------------------------------
1 |
11 | array (
12 | 'app\\' => 4,
13 | ),
14 | );
15 |
16 | public static $prefixDirsPsr4 = array (
17 | 'app\\' =>
18 | array (
19 | 0 => __DIR__ . '/../..' . '/',
20 | ),
21 | );
22 |
23 | public static $classMap = array (
24 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
25 | );
26 |
27 | public static function getInitializer(ClassLoader $loader)
28 | {
29 | return \Closure::bind(function () use ($loader) {
30 | $loader->prefixLengthsPsr4 = ComposerStaticInitd4e167bbb381ca3cc629eccfb7622e38::$prefixLengthsPsr4;
31 | $loader->prefixDirsPsr4 = ComposerStaticInitd4e167bbb381ca3cc629eccfb7622e38::$prefixDirsPsr4;
32 | $loader->classMap = ComposerStaticInitd4e167bbb381ca3cc629eccfb7622e38::$classMap;
33 |
34 | }, null, ClassLoader::class);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/vendor/composer/installed.json:
--------------------------------------------------------------------------------
1 | {
2 | "packages": [],
3 | "dev": true,
4 | "dev-package-names": []
5 | }
6 |
--------------------------------------------------------------------------------
/vendor/composer/installed.php:
--------------------------------------------------------------------------------
1 |
3 | array (
4 | 'pretty_version' => '1.0.0+no-version-set',
5 | 'version' => '1.0.0.0',
6 | 'aliases' =>
7 | array (
8 | ),
9 | 'reference' => NULL,
10 | 'name' => 'raeen/phpy',
11 | ),
12 | 'versions' =>
13 | array (
14 | 'raeen/phpy' =>
15 | array (
16 | 'pretty_version' => '1.0.0+no-version-set',
17 | 'version' => '1.0.0.0',
18 | 'aliases' =>
19 | array (
20 | ),
21 | 'reference' => NULL,
22 | ),
23 | ),
24 | );
25 |
--------------------------------------------------------------------------------