diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..d75a585 --- /dev/null +++ b/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine on +RewriteRule ^$ public/ [L] +RewriteRule (.*) public/$1 [L] \ No newline at end of file diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php deleted file mode 100644 index bc7a0e5..0000000 --- a/app/Http/Controllers/BaseController.php +++ /dev/null @@ -1,13 +0,0 @@ -lol(); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 0000000..ce74c07 --- /dev/null +++ b/app/Http/Controllers/HomeController.php @@ -0,0 +1,19 @@ + 'Dit is een test']); + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json index 392c77c..4dab96f 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,10 @@ ], "license": "MIT", "require": { - "php": "^7.2" + "php": "^7.2", + "ext-json": "*", + "pecee/simple-router": "4.2.0.6", + "twig/twig": "^3.0" }, "config": { "optimize-autoloader": true, @@ -18,7 +21,10 @@ "psr-4": { "Runtime\\": "src/Runtime/", "App\\": "app/" - } + }, + "files": [ + "src/Runtime/Helpers/helpers.php" + ] }, "minimum-stability": "dev", "prefer-stable": true diff --git a/composer.lock b/composer.lock index b46a71d..c3d7e27 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,656 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6de065434f40becaf0a1e74d6aaff7a9", - "packages": [], + "content-hash": "d96c3c8dad22cc886c62ad330566ecbc", + "packages": [ + { + "name": "jeremeamia/superclosure", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/jeremeamia/super_closure.git", + "reference": "5707d5821b30b9a07acfb4d76949784aaa0e9ce9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jeremeamia/super_closure/zipball/5707d5821b30b9a07acfb4d76949784aaa0e9ce9", + "reference": "5707d5821b30b9a07acfb4d76949784aaa0e9ce9", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^1.2|^2.0|^3.0|^4.0", + "php": ">=5.4", + "symfony/polyfill-php56": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0|^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-4": { + "SuperClosure\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia", + "role": "Developer" + } + ], + "description": "Serialize Closure objects, including their context and binding", + "homepage": "https://github.com/jeremeamia/super_closure", + "keywords": [ + "closure", + "function", + "lambda", + "parser", + "serializable", + "serialize", + "tokenizer" + ], + "time": "2018-03-21T22:21:57+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v4.3.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/9a9981c347c5c49d6dfe5cf826bb882b824080dc", + "reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "0.0.5", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2019-11-08T13:50:10+00:00" + }, + { + "name": "pecee/simple-router", + "version": "4.2.0.6", + "source": { + "type": "git", + "url": "https://github.com/skipperbent/simple-php-router.git", + "reference": "b715c48415d5e3660df668350152bba8798a6e33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/skipperbent/simple-php-router/zipball/b715c48415d5e3660df668350152bba8798a6e33", + "reference": "b715c48415d5e3660df668350152bba8798a6e33", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=7.1", + "php-di/php-di": "^6.0" + }, + "require-dev": { + "mockery/mockery": "^1", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Pecee\\": "src/Pecee/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Simon Sessingø", + "email": "simon.sessingoe@gmail.com" + } + ], + "description": "Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.", + "keywords": [ + "framework", + "input-handler", + "laravel", + "pecee", + "php", + "request-handler", + "route", + "router", + "routing", + "routing-engine", + "simple-php-router", + "url-handling" + ], + "time": "2018-11-24T23:47:02+00:00" + }, + { + "name": "php-di/invoker", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/Invoker.git", + "reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/540c27c86f663e20fe39a24cd72fa76cdb21d41a", + "reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a", + "shasum": "" + }, + "require": { + "psr/container": "~1.0" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "phpunit/phpunit": "~4.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Invoker\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Generic and extensible callable invoker", + "homepage": "https://github.com/PHP-DI/Invoker", + "keywords": [ + "callable", + "dependency", + "dependency-injection", + "injection", + "invoke", + "invoker" + ], + "time": "2017-03-20T19:28:22+00:00" + }, + { + "name": "php-di/php-di", + "version": "6.0.11", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/PHP-DI.git", + "reference": "9bdcc2f41f5fb700ddd01bc4fa8d5bd7b3f94620" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/9bdcc2f41f5fb700ddd01bc4fa8d5bd7b3f94620", + "reference": "9bdcc2f41f5fb700ddd01bc4fa8d5bd7b3f94620", + "shasum": "" + }, + "require": { + "jeremeamia/superclosure": "^2.0", + "nikic/php-parser": "^2.0|^3.0|^4.0", + "php": ">=7.0.0", + "php-di/invoker": "^2.0", + "php-di/phpdoc-reader": "^2.0.1", + "psr/container": "^1.0" + }, + "provide": { + "psr/container-implementation": "^1.0" + }, + "require-dev": { + "doctrine/annotations": "~1.2", + "friendsofphp/php-cs-fixer": "^2.4", + "mnapoli/phpunit-easymock": "~1.0", + "ocramius/proxy-manager": "~2.0.2", + "phpstan/phpstan": "^0.9.2", + "phpunit/phpunit": "~6.4" + }, + "suggest": { + "doctrine/annotations": "Install it if you want to use annotations (version ~1.2)", + "ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~2.0)" + }, + "type": "library", + "autoload": { + "psr-4": { + "DI\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "The dependency injection container for humans", + "homepage": "http://php-di.org/", + "keywords": [ + "PSR-11", + "container", + "container-interop", + "dependency injection", + "di", + "ioc", + "psr11" + ], + "time": "2019-12-12T07:58:02+00:00" + }, + { + "name": "php-di/phpdoc-reader", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/PhpDocReader.git", + "reference": "15678f7451c020226807f520efb867ad26fbbfcf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/PhpDocReader/zipball/15678f7451c020226807f520efb867ad26fbbfcf", + "reference": "15678f7451c020226807f520efb867ad26fbbfcf", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.6" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpDocReader\\": "src/PhpDocReader" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)", + "keywords": [ + "phpdoc", + "reflection" + ], + "time": "2019-09-26T11:24:58+00:00" + }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", + "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2019-11-27T13:56:44+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7b4aab9743c30be783b73de055d24a39cf4b954f", + "reference": "7b4aab9743c30be783b73de055d24a39cf4b954f", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2019-11-27T14:18:11+00:00" + }, + { + "name": "symfony/polyfill-php56", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php56.git", + "reference": "53dd1cdf3cb986893ccf2b96665b25b3abb384f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/53dd1cdf3cb986893ccf2b96665b25b3abb384f4", + "reference": "53dd1cdf3cb986893ccf2b96665b25b3abb384f4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-util": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php56\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2019-11-27T13:56:44+00:00" + }, + { + "name": "symfony/polyfill-util", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-util.git", + "reference": "964a67f293b66b95883a5ed918a65354fcd2258f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/964a67f293b66b95883a5ed918a65354fcd2258f", + "reference": "964a67f293b66b95883a5ed918a65354fcd2258f", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Util\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony utilities for portability of PHP codes", + "homepage": "https://symfony.com", + "keywords": [ + "compat", + "compatibility", + "polyfill", + "shim" + ], + "time": "2019-11-27T13:56:44+00:00" + }, + { + "name": "twig/twig", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "9b58bb8ac7a41d72fbb5a7dc643e07923e5ccc26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/9b58bb8ac7a41d72fbb5a7dc643e07923e5ccc26", + "reference": "9b58bb8ac7a41d72fbb5a7dc643e07923e5ccc26", + "shasum": "" + }, + "require": { + "php": "^7.2.9", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" + }, + "require-dev": { + "psr/container": "^1.0", + "symfony/debug": "^3.4|^4.2|^5.0", + "symfony/phpunit-bridge": "^4.4@dev|^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "homepage": "https://twig.symfony.com/contributors", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ], + "time": "2019-11-15T20:38:32+00:00" + } + ], "packages-dev": [], "aliases": [], "minimum-stability": "dev", @@ -13,7 +661,8 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.2" + "php": "^7.2", + "ext-json": "*" }, "platform-dev": [] } diff --git a/index.php b/index.php deleted file mode 100644 index 6d010cd..0000000 --- a/index.php +++ /dev/null @@ -1,5 +0,0 @@ -handle(); \ No newline at end of file diff --git a/public/web.config b/public/web.config new file mode 100644 index 0000000..7f5983b --- /dev/null +++ b/public/web.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/views/index.html b/resources/views/index.html new file mode 100644 index 0000000..d444486 --- /dev/null +++ b/resources/views/index.html @@ -0,0 +1 @@ +Werkt het: {{ test }} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index e69de29..404f163 100644 --- a/routes/web.php +++ b/routes/web.php @@ -0,0 +1,6 @@ +name('index'); +SimpleRouter::get('/test', 'HomeController@test')->name('test'); \ No newline at end of file diff --git a/src/Runtime/Bootstrap.php b/src/Runtime/Bootstrap.php index cfaf2c2..58f8cc5 100644 --- a/src/Runtime/Bootstrap.php +++ b/src/Runtime/Bootstrap.php @@ -2,27 +2,40 @@ namespace Runtime; -use App\Http\Controllers\BaseController; +use Runtime\Factory\BootstrapFactory; class Bootstrap { + /** + * @var BootstrapFactory + */ + private static $instance; + /** * Start handling process * - * @return string + * @return BootstrapFactory */ - public static function handle() { - return (new Bootstrap())->run(); - } - - private $base; - - public function __construct() + public static function createInstance() { - $this->base = new BaseController(); + self::$instance = (new Bootstrap())->run(); + + return Bootstrap::getInstance(); } - protected function run() { - return $this->base->test(); + /** + * @return BootstrapFactory + */ + public static function getInstance() + { + return self::$instance; + } + + /** + * @return BootstrapFactory + */ + protected function run() + { + return new BootstrapFactory(); } } \ No newline at end of file diff --git a/src/Runtime/Contracts/Container/Container.php b/src/Runtime/Contracts/Container/Container.php new file mode 100644 index 0000000..cd3e4f6 --- /dev/null +++ b/src/Runtime/Contracts/Container/Container.php @@ -0,0 +1,14 @@ +getMessage(); + die(); + } + + echo 'Error: ' . $abstract; + } + +} + diff --git a/src/Runtime/Factory/BootstrapFactory.php b/src/Runtime/Factory/BootstrapFactory.php new file mode 100644 index 0000000..cc0d22d --- /dev/null +++ b/src/Runtime/Factory/BootstrapFactory.php @@ -0,0 +1,47 @@ +resolve($abstract); + } + + /** + * @param $abstract + * @return mixed|null + */ + private function resolve($abstract) { + if(class_exists($abstract)) { + return new $abstract; + } + + ExceptionHandler::make(ClassNotFoundException::class); + return null; + } + +} \ No newline at end of file diff --git a/src/Runtime/Helpers/helpers.php b/src/Runtime/Helpers/helpers.php new file mode 100644 index 0000000..c056c91 --- /dev/null +++ b/src/Runtime/Helpers/helpers.php @@ -0,0 +1,35 @@ +make($abstract); + } +} + +if(!function_exists('view')) +{ + /** + * @param $name + * @param array $arguments + * @return mixed + */ + function view($name, $arguments = []) + { + $factory = app(ViewFactory::class); + + return $factory->make($name, $arguments); + } +} \ No newline at end of file diff --git a/src/Runtime/Http/Views/Factory.php b/src/Runtime/Http/Views/Factory.php new file mode 100644 index 0000000..9660d42 --- /dev/null +++ b/src/Runtime/Http/Views/Factory.php @@ -0,0 +1,95 @@ +resourcesDir . 'views'); + $this->twig = new Environment($loader, [ + 'cache' => $this->resourcesDir . 'cache' + ]); + } + + /** + * @param $name + * @param array $arguments + */ + public function make($name, $arguments = []) + { + $this->name = $this->name($name); + $this->arguments = $arguments; + + if(!$this->exists()) { + throw new ClassNotFoundException(); + } + + $this->render(); + + //TODO: Catch errors + } + + /** + * @return bool + */ + private function exists() + { + $file = getcwd() . "/../resources/views/{$this->name}.html"; + //TODO: Add checker + return true; + } + + /** + * @param $name + * @param $arguments + * @throws LoaderError + * @throws RuntimeError + * @throws SyntaxError + */ + private function render() + { + echo $this->twig->render($this->name . '.html', $this->arguments); + } + + /** + * @param $name + * @return string|string[] + */ + private function name($name) + { + return str_replace('.', '/', $name); + } +} \ No newline at end of file