1
0
Fork 0
mirror of synced 2024-06-13 16:24:47 +12:00

Moved preloaded to a seperate lib

This commit is contained in:
Eldad Fux 2020-08-14 20:41:03 +03:00
parent cc0004e23c
commit 0b5e24133d
4 changed files with 117 additions and 191 deletions

View file

@ -16,7 +16,7 @@ if (file_exists(__DIR__.'/../vendor/autoload.php')) {
require __DIR__.'/../vendor/autoload.php';
}
use Appwrite\Preloader\Preloader;
use Utopia\Preloader\Preloader;
include __DIR__.'/controllers/general.php';

View file

@ -42,6 +42,7 @@
"utopia-php/locale": "0.3.*",
"utopia-php/registry": "0.2.*",
"utopia-php/domains": "0.2.*",
"utopia-php/preloader": "0.1.*",
"resque/php-resque": "1.3.6",
"geoip2/geoip2": "2.9.0",

166
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e784e5988f3c65a561242b2ab64d7a31",
"content-hash": "a95c05370522cef7f6042467a9adf219",
"packages": [
{
"name": "appwrite/php-clamav",
@ -198,21 +198,21 @@
},
{
"name": "dasprid/enum",
"version": "1.0.0",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/DASPRiD/Enum.git",
"reference": "631ef6e638e9494b0310837fa531bedd908fc22b"
"reference": "6ccc0d7141a7f149e3c56cb0ce5f05d9152cfd07"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/DASPRiD/Enum/zipball/631ef6e638e9494b0310837fa531bedd908fc22b",
"reference": "631ef6e638e9494b0310837fa531bedd908fc22b",
"url": "https://api.github.com/repos/DASPRiD/Enum/zipball/6ccc0d7141a7f149e3c56cb0ce5f05d9152cfd07",
"reference": "6ccc0d7141a7f149e3c56cb0ce5f05d9152cfd07",
"shasum": ""
},
"require-dev": {
"phpunit/phpunit": "^6.4",
"squizlabs/php_codesniffer": "^3.1"
"phpunit/phpunit": "^7 | ^8 | ^9",
"squizlabs/php_codesniffer": "^3.4"
},
"type": "library",
"autoload": {
@ -228,7 +228,8 @@
{
"name": "Ben Scholzen 'DASPRiD'",
"email": "mail@dasprids.de",
"homepage": "https://dasprids.de/"
"homepage": "https://dasprids.de/",
"role": "Developer"
}
],
"description": "PHP 7.1 enum implementation",
@ -236,7 +237,7 @@
"enum",
"map"
],
"time": "2017-10-25T22:45:27+00:00"
"time": "2020-07-30T16:37:13+00:00"
},
{
"name": "domnikl/statsd",
@ -638,29 +639,29 @@
},
{
"name": "maxmind-db/reader",
"version": "v1.6.0",
"version": "v1.7.0",
"source": {
"type": "git",
"url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git",
"reference": "febd4920bf17c1da84cef58e56a8227dfb37fbe4"
"reference": "942553da239f12051275f9c666538b5dd09e2908"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/febd4920bf17c1da84cef58e56a8227dfb37fbe4",
"reference": "febd4920bf17c1da84cef58e56a8227dfb37fbe4",
"url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/942553da239f12051275f9c666538b5dd09e2908",
"reference": "942553da239f12051275f9c666538b5dd09e2908",
"shasum": ""
},
"require": {
"php": ">=5.6"
"php": ">=7.2"
},
"conflict": {
"ext-maxminddb": "<1.6.0,>=2.0.0"
"ext-maxminddb": "<1.7.0,>=2.0.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "2.*",
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpcov": "^3.0",
"phpunit/phpunit": "5.*",
"phpunit/phpcov": ">=6.0.0",
"phpunit/phpunit": ">=8.0.0,<10.0.0",
"squizlabs/php_codesniffer": "3.*"
},
"suggest": {
@ -694,7 +695,7 @@
"geolocation",
"maxmind"
],
"time": "2019-12-19T22:59:03+00:00"
"time": "2020-08-07T22:10:05+00:00"
},
{
"name": "maxmind/web-service-common",
@ -898,28 +899,32 @@
},
{
"name": "piwik/device-detector",
"version": "3.5.1",
"version": "3.12.6",
"source": {
"type": "git",
"url": "https://github.com/matomo-org/device-detector.git",
"reference": "29830f9bd67c8300e37828db0688161dd6f5f7a5"
"reference": "4eb7b6d4d1a2ac1e8fee64fc73698fcb869d60f3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/29830f9bd67c8300e37828db0688161dd6f5f7a5",
"reference": "29830f9bd67c8300e37828db0688161dd6f5f7a5",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/4eb7b6d4d1a2ac1e8fee64fc73698fcb869d60f3",
"reference": "4eb7b6d4d1a2ac1e8fee64fc73698fcb869d60f3",
"shasum": ""
},
"require": {
"mustangostang/spyc": "*",
"php": ">=5.3.2"
"php": ">=5.5"
},
"require-dev": {
"fabpot/php-cs-fixer": "~1.7",
"phpunit/phpunit": "4.1.*"
"matthiasmullie/scrapbook": "@stable",
"phpunit/phpunit": "^4.8.36",
"psr/cache": "^1.0",
"psr/simple-cache": "^1.0"
},
"suggest": {
"doctrine/cache": "Can directly be used for caching purpose"
"doctrine/cache": "Can directly be used for caching purpose",
"ext-yaml": "Necessary for using the Pecl YAML parser"
},
"type": "library",
"autoload": {
@ -929,23 +934,23 @@
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0+"
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "The Piwik Team",
"email": "hello@piwik.org",
"homepage": "http://piwik.org/the-piwik-team/"
"name": "The Matomo Team",
"email": "hello@matomo.org",
"homepage": "https://matomo.org/team/"
}
],
"description": "The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.",
"homepage": "http://piwik.org",
"homepage": "https://matomo.org",
"keywords": [
"devicedetection",
"parser",
"useragent"
],
"time": "2016-01-21T22:26:37+00:00"
"time": "2020-06-16T12:10:46+00:00"
},
{
"name": "psr/http-message",
@ -1169,12 +1174,12 @@
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-idn.git",
"reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe"
"reference": "045643b91eaa34c4c37150ac477765c13552af33"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/bc6549d068d0160e0f10f7a5a23c7d1406b95ebe",
"reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/045643b91eaa34c4c37150ac477765c13552af33",
"reference": "045643b91eaa34c4c37150ac477765c13552af33",
"shasum": ""
},
"require": {
@ -1246,7 +1251,7 @@
"type": "tidelift"
}
],
"time": "2020-07-14T12:35:20+00:00"
"time": "2020-08-04T21:02:56+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
@ -1766,16 +1771,16 @@
},
{
"name": "utopia-php/framework",
"version": "0.8.3",
"version": "0.8.4",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/framework.git",
"reference": "e21725bdb52c93dc4b0acade33f03e098f0ceae7"
"reference": "c5add2ac2cd31286bb086f19dd66cfaed00f9a85"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/e21725bdb52c93dc4b0acade33f03e098f0ceae7",
"reference": "e21725bdb52c93dc4b0acade33f03e098f0ceae7",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/c5add2ac2cd31286bb086f19dd66cfaed00f9a85",
"reference": "c5add2ac2cd31286bb086f19dd66cfaed00f9a85",
"shasum": ""
},
"require": {
@ -1806,7 +1811,7 @@
"php",
"upf"
],
"time": "2020-07-09T06:39:23+00:00"
"time": "2020-08-06T10:52:23+00:00"
},
{
"name": "utopia-php/locale",
@ -1854,6 +1859,54 @@
],
"time": "2020-06-29T20:53:16+00:00"
},
{
"name": "utopia-php/preloader",
"version": "0.1.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/preloader.git",
"reference": "43e126b6c056e9a2c6a6f31f996f774e0072a22f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/preloader/zipball/43e126b6c056e9a2c6a6f31f996f774e0072a22f",
"reference": "43e126b6c056e9a2c6a6f31f996f774e0072a22f",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Utopia\\Preloader\\": "src/Preloader"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Eldad Fux",
"email": "team@appwrite.io"
}
],
"description": "Utopia Preloader library is simple and lite library for managing PHP preloading configuration",
"keywords": [
"framework",
"php",
"preload",
"preloader",
"preloading",
"upf",
"utopia"
],
"time": "2020-08-14T17:34:39+00:00"
},
{
"name": "utopia-php/registry",
"version": "0.2.3",
@ -1909,7 +1962,7 @@
"source": {
"type": "git",
"url": "https://github.com/appwrite/sdk-generator",
"reference": "4b3c02e27cb701f60406a4eac1c9561fd093d72a"
"reference": "43d15fc337bcbfe480f2a5503bd7c0615743035b"
},
"require": {
"ext-curl": "*",
@ -1939,7 +1992,7 @@
}
],
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
"time": "2020-07-10T07:50:52+00:00"
"time": "2020-07-26T09:32:03+00:00"
},
{
"name": "doctrine/instantiator",
@ -2311,12 +2364,12 @@
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "eb3320ef010709f339f118dde1645e197c4961ec"
"reference": "584a54ca0dadeee4e07c959e24fe61ffa4df22a2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/eb3320ef010709f339f118dde1645e197c4961ec",
"reference": "eb3320ef010709f339f118dde1645e197c4961ec",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/584a54ca0dadeee4e07c959e24fe61ffa4df22a2",
"reference": "584a54ca0dadeee4e07c959e24fe61ffa4df22a2",
"shasum": ""
},
"require": {
@ -2355,7 +2408,7 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2020-07-09T12:42:26+00:00"
"time": "2020-08-12T17:52:10+00:00"
},
{
"name": "phpdocumentor/type-resolver",
@ -2671,7 +2724,7 @@
},
{
"name": "phpunit/php-token-stream",
"version": "3.1.1",
"version": "3.1.x-dev",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
@ -2716,6 +2769,7 @@
"keywords": [
"tokenizer"
],
"abandoned": true,
"time": "2019-09-17T06:23:10+00:00"
},
{
@ -3607,12 +3661,12 @@
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "e063bab1a67f4ceea759cee20c10ed609d1f6abb"
"reference": "b531196d8cfaa485d7ff84d37b19668d8d6b254b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/e063bab1a67f4ceea759cee20c10ed609d1f6abb",
"reference": "e063bab1a67f4ceea759cee20c10ed609d1f6abb",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/b531196d8cfaa485d7ff84d37b19668d8d6b254b",
"reference": "b531196d8cfaa485d7ff84d37b19668d8d6b254b",
"shasum": ""
},
"require": {
@ -3664,7 +3718,17 @@
"keywords": [
"templating"
],
"time": "2020-07-06T13:35:12+00:00"
"funding": [
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/twig/twig",
"type": "tidelift"
}
],
"time": "2020-08-13T14:11:59+00:00"
},
{
"name": "webmozart/assert",

View file

@ -1,139 +0,0 @@
<?php
namespace Appwrite\Preloader;
class Preloader
{
/**
* @var array
*/
protected $ignores = [];
/**
* @var array
*/
protected $paths = [];
/**
* @var array
*/
protected $included = [];
public function __construct(string ...$paths)
{
$this->paths = $paths;
$classMap = require __DIR__.'/../../../vendor/composer/autoload_classmap.php';
$this->paths = \array_merge(
$this->paths,
\array_values($classMap)
);
}
public function paths(string ...$paths): self
{
$this->paths = \array_merge(
$this->paths,
$paths
);
return $this;
}
public function ignore(string ...$names): self
{
foreach($names as $name) {
if(is_readable($name)) {
$this->ignores[] = $name;
}
else {
echo "[Preloader] Failed to ignore path `{$name}`".PHP_EOL;
}
}
return $this;
}
public function load(): void
{
$this->included = get_included_files();
foreach ($this->paths as $path) {
$this->loadPath(\rtrim($path, '/'));
}
$already = count($this->included);
echo "[Preloader] Preloaded {$already} files.".PHP_EOL;
}
private function loadPath(string $path): void
{
if (\is_dir($path)) {
$this->loadDir($path);
return;
}
$this->loadFile($path);
}
private function loadDir(string $path): void
{
$handle = \opendir($path);
while ($file = \readdir($handle)) {
if (\in_array($file, ['.', '..'])) {
continue;
}
$this->loadPath("{$path}/{$file}");
}
\closedir($handle);
}
private function loadFile(string $path): void
{
if ($this->shouldIgnore($path)) {
return;
}
if(in_array(realpath($path), $this->included)) {
// echo "[Preloader] Skiped `{$path}`".PHP_EOL;
return;
}
// echo "[Preloader] Preloaded `{$path}`".PHP_EOL;
try {
// opcache_compile_file($path);
require $path;
} catch (\Throwable $th) {
echo "[Preloader] Failed to load `{$path}`: ".$th->getMessage().PHP_EOL;
return;
}
$this->included = array_merge(get_included_files(), [realpath($path)]);
}
private function shouldIgnore(?string $path): bool
{
if($path === null) {
return true;
}
if(!\in_array(\pathinfo($path, PATHINFO_EXTENSION), ['php'])) {
return true;
}
foreach ($this->ignores as $ignore) {
if (\strpos($path, $ignore) === 0) {
return true;
}
}
return false;
}
}