~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to bin/run.php

  • Committer: Dan Garner
  • Date: 2015-03-26 14:08:33 UTC
  • Revision ID: git-v1:70d14044444f8dc5d602b99890d59dea46d9470c
Moved web servable files to web folder

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2016 Spring Signage Ltd
5
 
 * (run.php)
6
 
 *
7
 
 * Xibo is free software: you can redistribute it and/or modify
8
 
 * it under the terms of the GNU Affero General Public License as published by
9
 
 * the Free Software Foundation, either version 3 of the License, or
10
 
 * any later version.
11
 
 *
12
 
 * Xibo is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU Affero General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Affero General Public License
18
 
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
19
 
 *
20
 
 * Console Runner
21
 
 */
22
 
 
23
 
define('XIBO', true);
24
 
define('PROJECT_ROOT', realpath(__DIR__ . '/..'));
25
 
 
26
 
error_reporting(0);
27
 
ini_set('display_errors', 0);
28
 
 
29
 
require PROJECT_ROOT . '/vendor/autoload.php';
30
 
 
31
 
if (!file_exists(PROJECT_ROOT . '/web/settings.php'))
32
 
    die('Not configured');
33
 
 
34
 
// convert all the command line arguments into a URL
35
 
$argv = $GLOBALS['argv'];
36
 
array_shift($GLOBALS['argv']);
37
 
$pathInfo = '/' . implode('/', $argv);
38
 
 
39
 
// Create a logger
40
 
$logger = new \Xibo\Helper\AccessibleMonologWriter(array(
41
 
    'name' => 'CONSOLE',
42
 
    'handlers' => array(
43
 
        new \Xibo\Helper\DatabaseLogHandler()
44
 
    ),
45
 
    'processors' => array(
46
 
        new \Xibo\Helper\LogProcessor(),
47
 
        new \Monolog\Processor\UidProcessor(7)
48
 
    )
49
 
), false);
50
 
 
51
 
$app = new \RKA\Slim(array(
52
 
    'debug' => false,
53
 
    'log.writer' => $logger
54
 
));
55
 
$app->setName('console');
56
 
 
57
 
// Config
58
 
$app->configService = \Xibo\Service\ConfigService::Load(PROJECT_ROOT . '/web/settings.php');
59
 
 
60
 
// Set up the environment so that Slim can route
61
 
$app->environment = Slim\Environment::mock([
62
 
    'PATH_INFO'   => $pathInfo
63
 
]);
64
 
 
65
 
// Twig templates
66
 
$twig = new \Slim\Views\Twig();
67
 
$twig->parserOptions = array(
68
 
    'debug' => true,
69
 
    'cache' => PROJECT_ROOT . '/cache'
70
 
);
71
 
$twig->parserExtensions = array(
72
 
    new \Slim\Views\TwigExtension(),
73
 
    new \Xibo\Twig\TransExtension(),
74
 
    new \Xibo\Twig\ByteFormatterTwigExtension(),
75
 
    new \Xibo\Twig\UrlDecodeTwigExtension(),
76
 
    new \Xibo\Twig\DateFormatTwigExtension()
77
 
);
78
 
 
79
 
// Configure the template folder
80
 
$twig->twigTemplateDirs = [PROJECT_ROOT . '/views'];
81
 
 
82
 
$app->view($twig);
83
 
 
84
 
\Xibo\Middleware\Storage::setStorage($app->container);
85
 
\Xibo\Middleware\State::setState($app);
86
 
$app->configService->loadTheme();
87
 
 
88
 
$app->add(new \Xibo\Middleware\Storage());
89
 
$app->add(new \Xibo\Middleware\Xmr());
90
 
 
91
 
// Handle additional Middleware
92
 
\Xibo\Middleware\State::setMiddleWare($app);
93
 
 
94
 
// Configure a user
95
 
$app->user = $app->userFactory->getSystemUser();
96
 
 
97
 
// Configure the Slim error handler
98
 
$app->error(function (\Exception $e) use ($app) {
99
 
    $app->container->get('\Xibo\Controller\Error')->handler($e);
100
 
});
101
 
 
102
 
// Configure a not found handler
103
 
$app->notFound(function () use ($app) {
104
 
    $app->container->get('\Xibo\Controller\Error')->notFound();
105
 
});
106
 
 
107
 
// All routes
108
 
$app->get('/', '\Xibo\Controller\Task:poll');
109
 
$app->get('/:id', '\Xibo\Controller\Task:run');
110
 
 
111
 
// Run app
112
 
$app->run();
113