use kanellov/assets-manager-middleware instead assets_manager module

parent de9df588
...@@ -193,6 +193,7 @@ It also provides the routes for home and about pages. ...@@ -193,6 +193,7 @@ It also provides the routes for home and about pages.
- `slim/csrf`: ^0.6.0 - `slim/csrf`: ^0.6.0
- `slim/flash`: ^0.1.0 - `slim/flash`: ^0.1.0
- `kanellov/slim-twig-flash`: ^0.1 - `kanellov/slim-twig-flash`: ^0.1
- `kanellov/assets-manager-middleware`: ^1.0,
- `monolog/monolog`: ^1.13 - `monolog/monolog`: ^1.13
### application_form ### application_form
...@@ -208,14 +209,6 @@ It also overrides schools index view by appending application form information. ...@@ -208,14 +209,6 @@ It also overrides schools index view by appending application form information.
- schools module - schools module
- `zendframework/zend-inputfilter`: ^2.0 - `zendframework/zend-inputfilter`: ^2.0
### assets_manager
A module that is responsible to serve asset files, like css and js from within module's directory. See [`assets_manager.global.php` in Slim settings files](#slim-settings-files).
#### Dependencies
None
### authentication ### authentication
Module that provides user authentication against database. The module includes the view for login page. Module that provides user authentication against database. The module includes the view for login page.
...@@ -302,13 +295,17 @@ This module provides the services, views and javascript for schools to submit th ...@@ -302,13 +295,17 @@ This module provides the services, views and javascript for schools to submit th
- application module - application module
- `zendframework/zend-inputfilter`: ^2.0 - `zendframework/zend-inputfilter`: ^2.0
## ER diagram
![ER diagram](https://github.com/eellak/gredu_labs/blob/develop/data/db/er.png)
## Run it: ## Run it:
1. `$ cd gredu_labs` 1. `$ cd gredu_labs`
2. `$ php -S 0.0.0.0:8888 -t public public/index.php` 2. `$ php -S 0.0.0.0:8888 -t public public/index.php`
3. Browse to http://localhost:8888 3. Browse to http://localhost:8888
**Warning:** assets_manager module does not work with php-server sapi. Assets from modules will have to be copied in `public` directory by hand. **Warning:** kanellov/assets-manager-middleware does not work with php-server sapi. Assets from modules will have to be copied in `public` directory by hand.
## Links ## Links
- [Slim Framework](http://www.slimframework.com/) - [Slim Framework](http://www.slimframework.com/)
...@@ -316,6 +313,7 @@ This module provides the services, views and javascript for schools to submit th ...@@ -316,6 +313,7 @@ This module provides the services, views and javascript for schools to submit th
- [slimphp/Slim-Flash](https://github.com/slimphp/Slim-Flash) - [slimphp/Slim-Flash](https://github.com/slimphp/Slim-Flash)
- [kanellov/config-merge](https://github.com/kanellov/config-merge) - [kanellov/config-merge](https://github.com/kanellov/config-merge)
- [kanellov/php-events](https://github.com/kanellov/php-events) - [kanellov/php-events](https://github.com/kanellov/php-events)
- [kanellov/assets-manager-middleware](https://github.com/kanellov/assets-manager-middleware)
- [monolog](https://github.com/Seldaek/monolog) - [monolog](https://github.com/Seldaek/monolog)
- [zendframework/zend-ldap](https://github.com/zendframework/zend-ldap) - [zendframework/zend-ldap](https://github.com/zendframework/zend-ldap)
- [zendframework/zend-authentication](https://github.com/zendframework/zend-authentication) - [zendframework/zend-authentication](https://github.com/zendframework/zend-authentication)
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "7c79ace2b611ee07037e18e4a4666341", "hash": "76a50cdfbc7976610314973fc6a6970c",
"content-hash": "3c852e2ae403fb0ca7c6817354967855", "content-hash": "392d1701bd480c4bd0e2e46da4adc693",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
...@@ -300,6 +300,57 @@ ...@@ -300,6 +300,57 @@
], ],
"time": "2015-11-16 20:44:36" "time": "2015-11-16 20:44:36"
}, },
{
"name": "kanellov/assets-manager-middleware",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/kanellov/assets-manager-middleware.git",
"reference": "96988de6c11f5f7cce0aef6a032904c2e45270a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kanellov/assets-manager-middleware/zipball/96988de6c11f5f7cce0aef6a032904c2e45270a8",
"reference": "96988de6c11f5f7cce0aef6a032904c2e45270a8",
"shasum": ""
},
"require": {
"php": ">=5.5",
"psr/http-message": "^1.0"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.*",
"phpunit/phpunit": "4.*",
"zendframework/zend-diactoros": "1.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Knlv\\Middleware\\": "src/",
"KnlvTest\\Middleware\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GNU GPLv3"
],
"authors": [
{
"name": "Vassilis Kanellopoulos",
"email": "contact@kanellov.com",
"homepage": "http://kanellov.com"
}
],
"description": "A middleware to serve assets from non public directories",
"homepage": "https://github.com/kanellov/assets-manager-middleware",
"keywords": [
"assets",
"library",
"middleware",
"psr7"
],
"time": "2016-03-07 09:41:32"
},
{ {
"name": "kanellov/config-merge", "name": "kanellov/config-merge",
"version": "dev-master", "version": "dev-master",
...@@ -842,16 +893,16 @@ ...@@ -842,16 +893,16 @@
}, },
{ {
"name": "slim/slim", "name": "slim/slim",
"version": "3.2.1", "version": "3.2.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/slimphp/Slim.git", "url": "https://github.com/slimphp/Slim.git",
"reference": "53a4dd576dd3add4efd113ca77c3c21fa559b33e" "reference": "1d99b8846c784d885201b2b709bfedb63656ed30"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/53a4dd576dd3add4efd113ca77c3c21fa559b33e", "url": "https://api.github.com/repos/slimphp/Slim/zipball/1d99b8846c784d885201b2b709bfedb63656ed30",
"reference": "53a4dd576dd3add4efd113ca77c3c21fa559b33e", "reference": "1d99b8846c784d885201b2b709bfedb63656ed30",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -905,7 +956,7 @@ ...@@ -905,7 +956,7 @@
"micro", "micro",
"router" "router"
], ],
"time": "2016-02-29 21:39:18" "time": "2016-03-05 19:36:16"
}, },
{ {
"name": "slim/twig-view", "name": "slim/twig-view",
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
return [ return [
'modules' => [ 'modules' => [
'module/application/bootstrap.php', 'module/application/bootstrap.php',
'module/assets_manager/bootstrap.php',
'module/authentication/bootstrap.php', 'module/authentication/bootstrap.php',
'module/authorization/bootstrap.php', 'module/authorization/bootstrap.php',
'module/sch_ldap/bootstrap.php', 'module/sch_ldap/bootstrap.php',
......
...@@ -11,8 +11,8 @@ return [ ...@@ -11,8 +11,8 @@ return [
'assets' => [ 'assets' => [
'web_dir' => __DIR__ . '/../../public', 'web_dir' => __DIR__ . '/../../public',
'paths' => [ 'paths' => [
'module/schools/public', __DIR__ . '/../../module/schools/public',
'module/application_form/public', __DIR__ . '/../../module/application_form/public',
], ],
], ],
]; ];
...@@ -89,6 +89,12 @@ return function (Slim\App $app) { ...@@ -89,6 +89,12 @@ return function (Slim\App $app) {
); );
}; };
$container['assets'] = function ($c) {
$settings = $c['settings']['assets'];
return new Knlv\Middleware\AssetsManager($settings);
};
$container[GrEduLabs\Application\Action\Index::class] = function ($c) { $container[GrEduLabs\Application\Action\Index::class] = function ($c) {
return new GrEduLabs\Application\Action\Index($c['view']); return new GrEduLabs\Application\Action\Index($c['view']);
}; };
...@@ -99,6 +105,8 @@ return function (Slim\App $app) { ...@@ -99,6 +105,8 @@ return function (Slim\App $app) {
$events('on', 'app.bootstrap', function ($app, $container) { $events('on', 'app.bootstrap', function ($app, $container) {
$app->add(function ($req, $res, $next) use ($container) { $app->add(function ($req, $res, $next) use ($container) {
$settings = $container->get('settings'); $settings = $container->get('settings');
$forumUrl = $settings['forum_url']; $forumUrl = $settings['forum_url'];
...@@ -111,4 +119,9 @@ return function (Slim\App $app) { ...@@ -111,4 +119,9 @@ return function (Slim\App $app) {
$app->get('/', GrEduLabs\Application\Action\Index::class)->setName('index'); $app->get('/', GrEduLabs\Application\Action\Index::class)->setName('index');
$app->get('/about', GrEduLabs\Application\Action\About::class)->setName('about'); $app->get('/about', GrEduLabs\Application\Action\About::class)->setName('about');
}); });
// low priority means add middleware last and for slim means run middleware first
$events('on', 'app.bootstrap', function ($app, $container) {
$app->add('assets');
}, -1000);
}; };
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Http\Response;
return function (Slim\App $app) {
$mimeTypes = [
'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',
// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',
// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
// ms office
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
];
$container = $app->getContainer();
$events = $container['events'];
$events('on', 'app.bootstrap', function ($app, $container) use ($mimeTypes) {
$app->add(function (
ServerRequestInterface $req,
ResponseInterface $res,
callable $next
) use ($mimeTypes, $container) {
$res = $next($req, $res);
if (404 === $res->getStatusCode()) {
$settings = $container['settings']['assets'];
$file = array_reduce($settings['paths'], function ($file, $path) use ($req) {
if (false !== $file) {
return $file;
}
$file = $path . $req->getUri()->getPath();
if (is_readable($file)) {
return $file;
}
return false;
}, false);
if (!$file) {
return $res;
}
$ext = strtolower(array_pop(explode('.', $file)));
$mime = array_key_exists($ext, $mimeTypes)
? $mimeTypes[$ext] : mime_content_type($file);
$contents = file_get_contents($file);
if (is_writable($settings['web_dir'])) {
$destFile = $settings['web_dir'] . $req->getUri()->getPath();
$destPath = dirname($destFile);
if (!is_dir($destPath)) {
mkdir($destPath);
}
file_put_contents($destFile, $contents);
}
$res = new Response(200);
$res->withHeader('Content-Type', $mime);
$res->getBody()->write($contents);
}
return $res;
});
}, -10000);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment