diff --git a/composer.json b/composer.json index d508ce8..5055331 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,8 @@ }, "scripts": { "start": "php -S 0.0.0.0:8080 -t public public/index.php" + }, + "autoload": { + "psr-4": {"InfD4p\\": "src/"} } - } diff --git a/composer.lock b/composer.lock index 4d8df69..2bcfdbd 100644 --- a/composer.lock +++ b/composer.lock @@ -8,18 +8,21 @@ "packages": [ { "name": "container-interop/container-interop", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/container-interop/container-interop.git", - "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" + "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", - "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", + "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", "shasum": "" }, + "require": { + "psr/container": "^1.0" + }, "type": "library", "autoload": { "psr-4": { @@ -31,7 +34,8 @@ "MIT" ], "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", - "time": "2014-12-30T15:22:37+00:00" + "homepage": "https://github.com/container-interop/container-interop", + "time": "2017-02-14T19:40:03+00:00" }, { "name": "nikic/fast-route", @@ -122,6 +126,55 @@ ], "time": "2015-09-11T15:10:35+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": "psr/http-message", "version": "1.0.1", diff --git a/public/index.php b/public/index.php index 2784ee0..105dcc1 100644 --- a/public/index.php +++ b/public/index.php @@ -1,4 +1,21 @@ run(); +include __DIR__ . '/../src/bootstrap.php'; diff --git a/src/Application/Main.php b/src/Application/Main.php new file mode 100644 index 0000000..33129b8 --- /dev/null +++ b/src/Application/Main.php @@ -0,0 +1,38 @@ +get('/[{name}]', function ($request, $response, $args) { + // Render index view + return $this->renderer->render($response, 'index.phtml', $args); + }); + } +} diff --git a/src/bootstrap.php b/src/bootstrap.php new file mode 100644 index 0000000..892723b --- /dev/null +++ b/src/bootstrap.php @@ -0,0 +1,88 @@ +getContainer(); + +// Create the view renderer +/** + * ============== + * INSTRUCTIEBLOK + * ============== + * + * Hier wordt de 'view renderer' aan de dependency container (zie hierboven) toegevoegd. Dit zorgt dat je in je applicatie deze 'view renderer' kunt gebruiken via `$this->renderer`. + * De renderer wordt gebruikt om een PHP template (https://en.wikipedia.org/wiki/Web_template_system) aan je URL te koppelen. + * + * Dit kun je doen in je 'route' (URL) met de volgende code: + * + * ``` + * return $this->renderer->render($response, 'index.phtml', $args); + * ``` + * + * (index.phtml kan hier vervangen worden door een template adres uit de map templates) + */ +$container['renderer'] = function ($c) { + $settings = $c->get('settings')['renderer']; + return new Slim\Views\PhpRenderer($settings['template_path']); +}; + +// Inject the application main class +/** + * ============== + * INSTRUCTIEBLOK + * ============== + * + * Hieronder wordt de Main class van onze applicatie aangeroepen. + * + * In object georiƫnteerd PHP is een applicatie vaak gestructureerd in meerdere 'classes', die ook wel objecten worden genoemd. Een object kan worden gemaakt door het volgende: + * + */ + +new InfD4p\Application\Main($app); + +/** + * Bij het maken van dit object is in de class de __construct functie aangeroepen met de parameter $app. De functies die daar in staan zullen nu worden uitgevoerd. + * + * Je kunt de class herkennen uit talen als Java en C(++ of #), omdat ze daar ook worden gebruikt. + * + * Je kunt voor een beter begrip de volgende sites lezen: + * - https://www.sitepoint.com/php-53-namespaces-basics/ (over namespaces (wij gebruiken InfD4p\Application)) + * - http://php.net/manual/en/language.oop5.basic.php (over de class) + */ + +// Run app +$app->run(); diff --git a/src/dependencies.php b/src/dependencies.php deleted file mode 100644 index af58864..0000000 --- a/src/dependencies.php +++ /dev/null @@ -1,10 +0,0 @@ -getContainer(); - -// view renderer -$container['renderer'] = function ($c) { - $settings = $c->get('settings')['renderer']; - return new Slim\Views\PhpRenderer($settings['template_path']); -}; diff --git a/src/middleware.php b/src/middleware.php deleted file mode 100644 index 116a0ff..0000000 --- a/src/middleware.php +++ /dev/null @@ -1,4 +0,0 @@ -add(new \Slim\Csrf\Guard); diff --git a/src/routes.php b/src/routes.php deleted file mode 100644 index ea11a20..0000000 --- a/src/routes.php +++ /dev/null @@ -1,7 +0,0 @@ -get('/[{name}]', function ($request, $response, $args) { - // Render index view - return $this->renderer->render($response, 'index.phtml', $args); -});