Initial commit with basic structure

This commit is contained in:
BackIsBachus
2017-09-17 08:09:11 +02:00
commit b0d0c4ebcc
26 changed files with 3587 additions and 0 deletions

45
.gitignore vendored Normal file
View File

@@ -0,0 +1,45 @@
/vendor/
# Cache and logs (Symfony2)
/app/cache/*
/app/logs/*
!app/cache/.gitkeep
!app/logs/.gitkeep
# Email spool folder
/app/spool/*
# Cache, session files and logs (Symfony3)
/var/cache/*
/var/logs/*
/var/sessions/*
!var/cache/.gitkeep
!var/logs/.gitkeep
!var/sessions/.gitkeep
# Parameters
/app/config/parameters.yml
/app/config/parameters.ini
# Managed by Composer
/app/bootstrap.php.cache
/var/bootstrap.php.cache
/bin/*
!bin/console
!bin/symfony_requirements
# Assets and user uploads
/web/bundles/
/web/uploads/
# PHPUnit
/app/phpunit.xml
/phpunit.xml
# Build data
/build/
# Backup entities generated with doctrine:generate:entities command
**/Entity/*~
# Embedded web-server pid file
/.web-server-pid

19
LICENSE Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2010-2017 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

77
README.rst Normal file
View File

@@ -0,0 +1,77 @@
Silex Skeleton
==============
Welcome to the Silex Skeleton - a fully-functional Silex application that you
can use as the skeleton for your new applications.
This document contains information on how to start using the Silex Skeleton.
Creating a Silex Application
----------------------------
Silex uses `Composer`_ to ease the creation of a new project:
.. code-block:: console
$ composer create-project fabpot/silex-skeleton path/to/install "~2.0"
Composer will create a new Silex project under the `path/to/install` directory.
Browsing the Demo Application
-----------------------------
Congratulations! You're now ready to use Silex.
To see a real-live Silex page in action, start the PHP built-in web server with
command:
.. code-block:: console
$ cd path/to/install
$ COMPOSER_PROCESS_TIMEOUT=0 composer run
Then, browse to http://localhost:8888/index_dev.php/
Getting started with Silex
--------------------------
This distribution is meant to be the starting point for your Silex applications.
A great way to start learning Silex is via the `Documentation`_, which will
take you through all the features of Silex.
What's inside?
---------------
The Silex Skeleton is configured with the following service providers:
* `ValidatorServiceProvider`_ - Provides a service for validating data. It is
most useful when used with the FormServiceProvider, but can also be used
standalone.
* `ServiceControllerServiceProvider`_ - As your Silex application grows, you
may wish to begin organizing your controllers in a more formal fashion.
Silex can use controller classes out of the box, but with a bit of work,
your controllers can be created as services, giving you the full power of
dependency injection and lazy loading.
* `TwigServiceProvider`_ - Provides integration with the Twig template engine.
* `WebProfilerServiceProvider`_ - Enable the Symfony web debug toolbar and
the Symfony profiler in your Silex application when developing.
* `MonologServiceProvider`_ - Enable logging in the development environment.
Read the `Providers`_ documentation for more details about Silex Service
Providers.
Enjoy!
.. _Composer: http://getcomposer.org/
.. _Documentation: http://silex.sensiolabs.org/documentation
.. _ValidatorServiceProvider: http://silex.sensiolabs.org/doc/master/providers/validator.html
.. _ServiceControllerServiceProvider: http://silex.sensiolabs.org/doc/master/providers/service_controller.html
.. _TwigServiceProvider: http://silex.sensiolabs.org/doc/master/providers/twig.html
.. _WebProfilerServiceProvider: http://github.com/silexphp/Silex-WebProfiler
.. _MonologServiceProvider: http://silex.sensiolabs.org/doc/master/providers/monolog.html
.. _Providers: http://silex.sensiolabs.org/doc/providers.html

16
bin/console Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php
require_once __DIR__.'/../vendor/autoload.php';
set_time_limit(0);
use Symfony\Component\Console\Input\ArgvInput;
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$app = require __DIR__.'/../src/app.php';
require __DIR__.'/../config/'.$env.'.php';
$console = require __DIR__.'/../src/console.php';
$console->run();

41
composer.json Normal file
View File

@@ -0,0 +1,41 @@
{
"name": "fabpot/silex-skeleton",
"description": "A pre-configured skeleton for the Silex microframework",
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"silex/silex": "~2.0",
"silex/web-profiler": "~2.0",
"symfony/asset": "~2.8|^3.0",
"symfony/browser-kit": "~2.8|^3.0",
"symfony/class-loader": "~2.8|^3.0",
"symfony/config": "~2.8|^3.0",
"symfony/console": "~2.8|^3.0",
"symfony/css-selector": "~2.8|^3.0",
"symfony/debug": "~2.8|^3.0",
"symfony/finder": "~2.8|^3.0",
"symfony/form": "~2.8|^3.0",
"symfony/monolog-bridge": "~2.8|^3.0",
"symfony/process": "~2.8|^3.0",
"symfony/security": "~2.8|^3.0",
"symfony/translation": "~2.8|^3.0",
"symfony/twig-bridge": "~2.8|^3.0",
"symfony/validator": "~2.8|^3.0",
"doctrine/dbal": "~2.2"
},
"autoload": {
"psr-0": { "": "src/" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"scripts": {
"run": [
"echo 'Started web server on http://localhost:8888'",
"php -S localhost:8888 -t web"
]
}
}

3038
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

18
config/dev.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
use Silex\Provider\MonologServiceProvider;
use Silex\Provider\WebProfilerServiceProvider;
// include the prod configuration
require __DIR__.'/prod.php';
// enable the debug mode
$app['debug'] = true;
$app->register(new MonologServiceProvider(), array(
'monolog.logfile' => __DIR__.'/../var/logs/silex_dev.log',
));
$app->register(new WebProfilerServiceProvider(), array(
'profiler.cache_dir' => __DIR__.'/../var/cache/profiler',
));

7
config/prod.php Normal file
View File

@@ -0,0 +1,7 @@
<?php
// configure your app for the production environment
$app['twig.path'] = array(__DIR__.'/../templates');
$app['twig.options'] = array('cache' => __DIR__.'/../var/cache/twig');
$app['db_config'] = array('path' => '/home/backisbachus/gw2/stats.db', 'records_table' => 'records', 'diff_table' => 'diff');

23
phpunit.xml.dist Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "vendor/autoload.php">
<testsuites>
<testsuite name="Test Suite">
<directory>src/</directory>
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>

37
src/app.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
use Silex\Application;
use Silex\Provider\AssetServiceProvider;
use Silex\Provider\TwigServiceProvider;
use Silex\Provider\ServiceControllerServiceProvider;
use Silex\Provider\HttpFragmentServiceProvider;
$app = new Application();
$app->register(new ServiceControllerServiceProvider());
$app->register(new AssetServiceProvider());
$app->register(new TwigServiceProvider());
$app->register(new HttpFragmentServiceProvider());
$app['twig'] = $app->extend('twig', function ($twig, $app) {
// add custom globals, filters, tags, ...
$displayRatio = new Twig_Function('displayRatio', function($k, $d) {
$out = "<span class='hint--rounded hint--top' ";
if($d == 0) {
$s = ($k>1)?"s":"";
$out .= "aria-label='0 death'>".$k." kill".$s;
} else if($k == 0) {
$s = ($d>1)?"s":"";
$out .= "aria-label='0 kill'>".$d." death".$s;
} else {
$sk = ($k>1)?"s":"";
$sd = ($d>1)?"s":"";
$out .= "aria-label='".$k." kill".$sk." | ".$d." death".$sd."'>".round($k/$d, 2);
}
$out .= "</span>";
return $out;
});
$twig->addFunction($displayRatio);
return $twig;
});
return $app;

23
src/console.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
$console = new Application('My Silex Application', 'n/a');
$console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
$console->setDispatcher($app['dispatcher']);
$console
->register('my-command')
->setDefinition(array(
// new InputOption('some-option', null, InputOption::VALUE_NONE, 'Some help'),
))
->setDescription('My command description')
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) {
// do something
})
;
return $console;

39
src/controllers.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
//Request::setTrustedProxies(array('127.0.0.1'));
$app->get('/', function () use ($app) {
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'db.options' => array(
'driver' => 'pdo_sqlite',
'path' => $app['db_config']['path'],
),
));
$sql = "SELECT * FROM ".$app['db_config']['diff_table']."";
$diffs = $app['db']->fetchAll($sql);
return $app['twig']->render('index.html.twig', array("diffs" => $diffs));
})
->bind('homepage')
;
$app->error(function (\Exception $e, Request $request, $code) use ($app) {
if ($app['debug']) {
return;
}
// 404.html, or 40x.html, or 4xx.html, or error.html
$templates = array(
'errors/'.$code.'.html.twig',
'errors/'.substr($code, 0, 2).'x.html.twig',
'errors/'.substr($code, 0, 1).'xx.html.twig',
'errors/default.html.twig',
);
return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
});

View File

@@ -0,0 +1,5 @@
{% extends "layout.html.twig" %}
{% block content %}
Page not found.
{% endblock %}

View File

@@ -0,0 +1,5 @@
{% extends "layout.html.twig" %}
{% block content %}
An error occurred on the client.
{% endblock %}

View File

@@ -0,0 +1,5 @@
{% extends "layout.html.twig" %}
{% block content %}
Internal server error.
{% endblock %}

View File

@@ -0,0 +1,5 @@
{% extends "layout.html.twig" %}
{% block content %}
An error occurred on the server.
{% endblock %}

View File

@@ -0,0 +1,5 @@
{% extends "layout.html.twig" %}
{% block content %}
An error occurred.
{% endblock %}

55
templates/index.html.twig Normal file
View File

@@ -0,0 +1,55 @@
{% extends "layout.html.twig" %}
{% block content %}
<p>
<table>
<col>
<colgroup span="3"></colgroup>
<colgroup span="3"></colgroup>
<thead>
<tr>
<td rowpsan="2"></td>
<th colspan="3" scope="colgroup">Eternal Battleground</th>
<th colspan="3" scope="colgroup">Red Borderland</th>
<th colspan="3" scope="colgroup">Blue Borderland</th>
<th colspan="3" scope="colgroup">Green Borderland</th>
</tr>
<tr>
<th scope="col">Start (CEST)</th>
<th scope="col" class="red">Red</th>
<th scope="col" class="blue">Blue</th>
<th scope="col" class="green">Green</th>
<th scope="col" class="red">Red</th>
<th scope="col" class="blue">Blue</th>
<th scope="col" class="green">Green</th>
<th scope="col" class="red">Red</th>
<th scope="col" class="blue">Blue</th>
<th scope="col" class="green">Green</th>
<th scope="col" class="red">Red</th>
<th scope="col" class="blue">Blue</th>
<th scope="col" class="green">Green</th>
</tr>
</thead>
<tbody>
{% for diff in diffs %}
<tr>
<th scope="row">{{diff.start|date("l H:i")}}</th>
<td class="red">{{displayRatio(diff.eb_r_k, diff.eb_r_d)|raw}}</td>
<td class="blue">{{displayRatio(diff.eb_b_k, diff.eb_b_d)|raw}}</td>
<td class="green">{{displayRatio(diff.eb_g_k, diff.eb_g_d)|raw}}</td>
<td class="red">{{displayRatio(diff.rh_r_k, diff.rh_r_d)|raw}}</td>
<td class="blue">{{displayRatio(diff.rh_b_k, diff.rh_b_d)|raw}}</td>
<td class="green">{{displayRatio(diff.rh_g_k, diff.rh_g_d)|raw}}</td>
<td class="red">{{displayRatio(diff.bh_r_k, diff.bh_r_d)|raw}}</td>
<td class="blue">{{displayRatio(diff.bh_b_k, diff.bh_b_d)|raw}}</td>
<td class="green">{{displayRatio(diff.bh_g_k, diff.bh_g_d)|raw}}</td>
<td class="red">{{displayRatio(diff.gh_r_k, diff.gh_r_d)|raw}}</td>
<td class="blue">{{displayRatio(diff.gh_b_k, diff.gh_b_d)|raw}}</td>
<td class="green">{{displayRatio(diff.gh_g_k, diff.gh_g_d)|raw}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</p>
{% endblock %}

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>{% block title '' %}WvW skimrish stats</title>
<link href="{{ asset('css/main.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('css/hint.min.css') }}" rel="stylesheet" type="text/css" />
<script type="text/javascript">
</script>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>

26
tests/controllersTest.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
use Silex\WebTestCase;
class controllersTest extends WebTestCase
{
public function testGetHomepage()
{
$client = $this->createClient();
$client->followRedirects(true);
$crawler = $client->request('GET', '/');
$this->assertTrue($client->getResponse()->isOk());
$this->assertContains('Welcome', $crawler->filter('body')->text());
}
public function createApplication()
{
$app = require __DIR__.'/../src/app.php';
require __DIR__.'/../config/dev.php';
require __DIR__.'/../src/controllers.php';
$app['session.test'] = true;
return $this->app = $app;
}
}

2
var/cache/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

2
var/logs/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

5
web/css/hint.min.css vendored Normal file

File diff suppressed because one or more lines are too long

39
web/css/main.css Normal file
View File

@@ -0,0 +1,39 @@
html { height: 100%;}
body {
font: 14px/1.8em 'Open Sans', Helvetica, Arial, Helvetica, sans-serif;
color: #444;
background #fff;
-webkit-font-smoothing: antialiased;
height: 100%;
}
table {
border-collapse: collapse;
border-spacing: 0;
border: thick solid;
}
td {
vertical-align: top;
text-align: center;
}
td, th {
border: solid 1px #222;
padding: 0.25em 0.5em;
}
th {
font-weight: bold;
text-align: center;
background: #eee;
}
.red {background-color:rgba(255,0,0,0.25);}
.blue {background-color:rgba(0,0,255,0.25);}
.green {background-color:rgba(0,255,0,0.25);}
thead {
border: thick solid;
}

13
web/index.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
ini_set('display_errors', 0);
require_once __DIR__.'/../vendor/autoload.php';
$app = require __DIR__.'/../src/app.php';
require __DIR__.'/../config/prod.php';
require __DIR__.'/../src/controllers.php';
$app['debug'] = true;
$app->run();

22
web/index_dev.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
use Symfony\Component\Debug\Debug;
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
require_once __DIR__.'/../vendor/autoload.php';
Debug::enable();
$app = require __DIR__.'/../src/app.php';
require __DIR__.'/../config/dev.php';
require __DIR__.'/../src/controllers.php';
$app->run();