application skeleton

parent e7ac07b9
nbproject
*.sublime-project
*.sublime-workspace
.phpintel
vendor
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
->notPath('data')
->filter(function (SplFileInfo $file) {
if (strstr($file->getPath(), 'compatibility')) {
return false;
}
});
$config = Symfony\CS\Config\Config::create();
$config->level(null);
$config->fixers(
array(
'braces',
'duplicate_semicolon',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'function_call_space',
'function_declaration',
'indentation',
'join_function',
'line_after_namespace',
'linefeed',
'lowercase_keywords',
'parenthesis',
'multiple_use',
'method_argument_space',
'object_operator',
'php_closing_tag',
'psr0',
'remove_lines_between_uses',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
'unused_use',
'visibility',
'whitespacy_lines',
'ternary_spaces',
'align_double_arrow',
'align_equals',
'concat_with_spaces',
'ordered_use',
'short_array_syntax',
'single_array_no_trailing_comma',
'multiline_array_trailing_comma',
'spaces_cast',
'return',
'double_arrow_multiline_whitespaces',
)
);
$config->finder($finder);
return $config;
\ No newline at end of file
# Development guide
## Install dependencies via composer
In the project folder run
$ ./composer.phar install
to install dependencies.
If you add any dependencies in `composer.json` file, run
$ ./composer.phar update
to install new dependencies.
## Directory structure
- `app`: Application code
- `app/src`: All class files that follow the psr-4 autoloading standard (_see autoload in composer.json_)
- `app/templates`: Twig template files
- `config`: Configuration files (_\*.local.php are deployment specific files and ignored by git_)
- `data/cache/twig`: Twig's autogenerated cache files
- `data/log`: Log files
- `public`: Webserver Document root
- `test`: Unit test files
- `vendor`: Composer dependencies
## Special files
- `public\index.php`: Appliction entry point
- `config\{,*.}{global,local}.php`: Configuration files; \*.global.php are loaded first and then can be overriden by \*.local.php
- `app/dependencies.php`: Wiring dependencies
- `app/middleware.php`: Application middleware
- `app/routes.php`: All application routes
## Run it:
1. `$ cd gredu_labs`
2. `$ php -S 0.0.0.0:8888 -t public public/index.php`
3. Browse to http://localhost:8888
This diff is collapsed.
<?php
$container = $app->getContainer();
// Twig
$container['view'] = function ($c) {
$settings = $c->get('settings');
$view = new \Slim\Views\Twig(
$settings['view']['template_path'],
$settings['view']['twig']
);
$view->addExtension(
new Slim\Views\TwigExtension($c->get('router'), $c->get('request')->getUri())
);
$view->addExtension(new Twig_Extension_Debug());
return $view;
};
// Flash messages
$container['flash'] = function ($c) {
return new \Slim\Flash\messages;
};
// Monolog
$container['logger'] = function ($c) {
$settings = $c->get('settings');
$logger = new \Monolog\Logger($settings['logger']['name']);
$logger->pushProcessor(new \Monolog\Processor\UidProcessor());
$logger->pushHandler(new \Monolog\Handler\StreamHandler(
$settings['logger']['path'],
\Monolog\Logger::DEBUG
));
return $logger;
};
<?php
// Application middleware
// e.g: $app->add(new \Slim\Csrf\Guard);
<?php
$app->get('/', function ($request, $response, $args) use ($app) {
$container = $app->getContainer();
$logger = $container['logger'];
$view = $container['view'];
$logger->info('Home page dispatched');
$view->render($response, 'home.twig');
return $response;
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>GrEduLabs</title>
<link href="{{ base_url() }}/css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>GrEduLabs</h1>
<div>Welcome!</div>
</body>
</html>
\ No newline at end of file
{
"name": "eellak/gredu_labs",
"type": "application",
"description": "",
"license": "GNU GPLv3",
"authors": [
{
"name": "Vassilis Kanellopoulos",
"email": "contact@kanellov.com",
"homepage": "http://kanellov.com"
},
{
"name": "Giorgos Tsakalos"
},
{
"name": "Nontas Aggelou"
}
],
"require": {
"php": ">=5.5",
"slim/slim": "^3.0",
"slim/twig-view": "^2.0",
"slim/flash": "^0.1.0",
"monolog/monolog": "^1.13",
"kanellov/config-merge": "dev-master"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.*",
"phpunit/PHPUnit": "4.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/phpcov": "2.*"
},
"autoload": {
"psr-4": {
"GrEdu\\": "app/src"
}
},
"autoload-dev": {
"psr-0": {
}
}
}
This diff is collapsed.
File added
*.local.php
\ No newline at end of file
<?php return [
'settings' => [
// Slim Settings
'determineRouteBeforeAppMiddleware' => false,
'displayErrorDetails' => false,
// View settings
'view' => [
'template_path' => __DIR__ . '/../app/templates',
'twig' => [
'cache' => __DIR__ . '/../data/cache/twig',
'debug' => true,
'auto_reload' => true,
],
],
// monolog settings
'logger' => [
'name' => 'app',
'path' => __DIR__ . '/../data/log/' . (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] . '/' : '') . 'app.log',
],
],
];
<?php return [];
\ No newline at end of file
*
!.gitignore
\ No newline at end of file
*
!.gitignore
\ No newline at end of file
# For production, put your rewrite rules directly into your VirtualHost
# directive and turn off AllowOverride.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
</IfModule>
<?php
chdir(dirname(__DIR__));
if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) {
return false;
}
require __DIR__ . '/../vendor/autoload.php';
session_start();
$app = new \Slim\App(Knlv\config_merge('config', ['global', 'local']));
require 'app/dependencies.php';
require 'app/middleware.php';
require 'app/routes.php';
$app->run();
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