Beispiel #1
0
/**
 * Routing function
 *
 * @param      string  $route  The given route to map
 */
function route($route)
{
    $path = explode('/', $route);
    $method = array_pop($path);
    $controller = ucfirst(array_pop($path)) . 'Controller';
    $deep = count($path);
    $currentDeep = 0;
    $route = __DIR__ . DIRECTORY_SEPARATOR . 'controllers';
    while ($currentDeep < $deep) {
        $route .= DIRECTORY_SEPARATOR . $path[$currentDeep++];
        if (!is_dir($route)) {
            header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400);
            die;
        }
    }
    $route .= DIRECTORY_SEPARATOR . $controller . '.php';
    if (stream_resolve_include_path($route) === false) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
        die(file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . '404NotFound.html'));
    }
    include_once $route;
    Ini::setIniFileName(Ini::INI_CONF_FILE);
    // If the print SQL debug mode is on start a buffer
    if (Ini::getParam('Console', 'printSql')) {
        ob_start();
    }
    $controllerPath = 'controllers\\' . $controller;
    $controllerInstance = new $controllerPath();
    $controllerInstance->{$method}();
}
 /**
  * Constructor that called the parent \Exception constructor
  *
  * @param      string                $message  Error message
  * @param      int                   $code     Error level
  * @param      \Exception|null       $previous Previous \Exception or \Error
  */
 public function __construct(string $message, int $code = 0, $previous = null)
 {
     parent::__construct($message, $code, $previous);
     Ini::setIniFileName('conf.ini');
     $this->logger = new Logger(Ini::getParam('Exception', 'implementedLogger'));
     $this->logger->log($code, $message, parent::getTrace());
 }
Beispiel #3
0
 /**
  * Constructor that takes the entity name as first parameter to call the parent constructor
  *
  * @param      string  $entityName  The entity name
  */
 public function __construct(string $entityName)
 {
     Ini::setIniFileName(static::ENTITIES_CONF_PATH . $entityName . '.ini');
     $this->conf = Ini::getAllParams();
     $this->entityName = $entityName;
     $this->parseConf();
 }
 /**
  * Constructor that take the file path as a first parameter, if omitted it loads the file path defined in the ini
  *
  * @param      string  $filePath  OPTIONAL the file path
  */
 public function __construct(string $filePath = null)
 {
     if ($filePath !== null && is_string($filePath)) {
         $this->filePath = $filePath;
     } else {
         $this->filePath = Ini::getParam('FileLogger', 'filePath');
     }
 }
 /**
  * Constructor that loads chat parameters
  */
 public function __construct()
 {
     Ini::setIniFileName(Ini::INI_CONF_FILE);
     $conf = Ini::getSectionParams('Room service');
     $this->serviceName = $conf['serviceName'];
     $this->chatServiceName = Ini::getParam('Chat service', 'serviceName');
     $this->logger = new Logger([Logger::CONSOLE]);
 }
 /**
  * Get the email template by its name
  *
  * @param      string      $templateName  The email template name
  *
  * @throws     \Exception  if the template is not found
  *
  * @return     string      The email template
  */
 public static function getEmailTemplate(string $templateName) : string
 {
     $templatePath = dirname(__FILE__, 3) . DIRECTORY_SEPARATOR . Ini::getParam('Web', 'emailsPath') . DIRECTORY_SEPARATOR . $templateName . '.php';
     if (stream_resolve_include_path($templatePath) === false) {
         throw new \Exception('"' . $templatePath . '" not find in email templates path');
     }
     return file_get_contents($templatePath);
 }
 /**
  * Constructor that loads chat parameters
  */
 public function __construct()
 {
     Ini::setIniFileName(Ini::INI_CONF_FILE);
     $this->logger = new Logger([Logger::CONSOLE]);
     $this->esIndex = Ini::getParam('ElasticSearch', 'index');
     $conf = Ini::getSectionParams('Chat service');
     $this->serviceName = $conf['serviceName'];
     $this->historicStep = $conf['historicStep'];
 }
 /**
  * Output a JSON response from a data array passed in parameter
  *
  * @param      array  $data   The data to output
  */
 public function JsonResponse(array $data)
 {
     Ini::setIniFileName(Ini::INI_CONF_FILE);
     // If the print SQL debug mode is on clean the buffer before output
     if (Ini::getParam('Console', 'printSql')) {
         ob_end_clean();
     }
     echo json_encode($data, true);
 }
 /**
  * Get the user latitude and longitude as array ['lat' => latitude, 'lon' => longitude] or empty array on error
  * using MaxMind database
  */
 public function getLocation()
 {
     try {
         $record = (new Reader(Ini::getParam('GeoIp', 'databasePath')))->city($_SERVER['REMOTE_ADDR']);
         $location = ['lat' => $record->location->latitude, 'lon' => $record->location->longitude];
     } catch (\Exception $e) {
         $location = [];
     } finally {
         $this->JsonResponse($location);
     }
 }
 /**
  * Call the parent constructor, merge the commands list and launch the console
  */
 public function __construct()
 {
     parent::__construct();
     parent::$COMMANDS = array_merge(parent::$COMMANDS, static::$SELF_COMMANDS);
     $this->deploymentConfiguration = Ini::getSectionParams('Deployment');
     $this->absoluteProjectRootPath = dirname(__FILE__, 5);
     $this->timeOffset = static::getTimezoneOffset('Greenwich');
     static::$PROJECT_MAIN_STRUCTURE[$this->deploymentConfiguration['remoteProjectRootDirectoryName']] = static::$PROJECT_MAIN_STRUCTURE['.'];
     unset(static::$PROJECT_MAIN_STRUCTURE['.']);
     static::out(PHP_EOL . 'Absolute project root path is "' . $this->absoluteProjectRootPath . '"' . PHP_EOL);
     $this->launchConsole();
 }
Beispiel #11
0
 /**
  * Echo shortcut but with a encoding conversion before output
  *
  * @param      string  $output  The string to output in the console
  * @param      string  $prefix  A prefix to add to teh output DEFAULT ''
  *
  * @static
  */
 public static function out(string $output, string $prefix = '')
 {
     Ini::setIniFileName(Ini::INI_CONF_FILE);
     $environment = Ini::getParam('Environment', 'environment');
     if (!isset($_SERVER['REQUEST_URI'])) {
         $environment = 'console';
     }
     switch ($environment) {
         case 'console':
             echo mb_convert_encoding($prefix . $output, static::$echoEncoding);
             break;
         case 'web':
             foreach (preg_split('/' . PHP_EOL . '/', ConsoleColors::unsetColor($output)) as $line) {
                 //                    Console::log($line);
                 echo $line;
             }
             break;
         default:
             echo $prefix . $output;
             break;
     }
 }
Beispiel #12
0
 /**
  * Utility method to reuse the same PDO instance at each call (work like a Singleton pattern)
  *
  * @static
  */
 private static function initialize()
 {
     Ini::setIniFileName(Ini::INI_CONF_FILE);
     if (static::$printSQL === null) {
         // Load default printSQL value
         static::$printSQL = Ini::getParam('Console', 'printSql');
     }
     try {
         if (static::$PDO === null) {
             if (static::$username !== '' && static::$password !== '') {
                 if (count(static::$options) > 0) {
                     static::$PDO = new \PDO(static::$dsn, static::$username, static::$password, static::$options);
                 } else {
                     static::$PDO = new \PDO(static::$dsn, static::$username, static::$password);
                 }
             } elseif (static::$dsn !== '') {
                 static::$PDO = new \PDO(static::$dsn);
             } else {
                 // Load default database parameters
                 $param = Ini::getSectionParams('Database');
                 static::$PDO = new \PDO($param['dsn'], $param['username'], $param['password'], $param['options']);
             }
             // Load default PDO parameters
             $params = Ini::getSectionParams('PDO');
             foreach ($params as $paramName => $paramValue) {
                 if (!is_numeric($paramValue)) {
                     $paramValue = constant('\\PDO::' . $paramValue);
                 }
                 static::$PDO->setAttribute(constant('\\PDO::' . $paramName), $paramValue);
             }
             static::setPDOStatement();
         }
     } catch (\Exception $e) {
         throw new Exception($e->getMessage(), Exception::$CRITICAL);
     }
 }
 /**
  * Check and sanitize the input field before setting the value and keep errors trace
  *
  * @param      string     $columnName  The column name
  * @param      string     $value       The new column value
  *
  * @return     string  The sanitized value
  *
  * @todo Global validateField in EntityManager with generic checks (size) and custom to define in entity ?
  */
 private function validateField(string $columnName, string $value) : string
 {
     if ($columnName !== 'password') {
         $value = trim($value);
     }
     $this->errors[$columnName] = array();
     $length = strlen($value);
     $maxLength = $this->entity->getColumnMaxSize($columnName);
     $name = _(strtolower(preg_replace('/([A-Z])/', ' $0', $columnName)));
     if (in_array($columnName, User::$mustDefinedFields) && $length === 0) {
         $this->errors[$columnName][] = _('The ' . $name . ' can\'t be empty');
     } elseif ($length > $maxLength) {
         $this->errors[$columnName][] = _('The ' . $name . ' size can\'t exceed ' . $maxLength . ' characters');
     }
     if ($this->entity->checkUniqueField($columnName, $value)) {
         $this->errors[$columnName][] = _('This ' . $name . ' is already used');
     }
     switch ($columnName) {
         case 'lastName':
             $value = ucwords(strtolower($value));
             $value = preg_replace('/ ( )*/', ' ', $value);
             break;
         case 'firstName':
             $value = ucfirst(strtolower($value));
             $value = preg_replace('/ ( )*(.)?/', '-' . strtoupper('$2'), $value);
             break;
         case 'pseudonym':
             if (in_array(strtolower($value), User::$pseudoBlackList)) {
                 $this->errors[$columnName][] = _('The pseudonym "' . $value . '" is not accepted');
             }
             foreach (User::$forbiddenPseudoCharacters as $forbiddenPseudoCharacter) {
                 if (strpos($value, $forbiddenPseudoCharacter) !== false) {
                     $this->errors[$columnName][] = _('The character "' . $forbiddenPseudoCharacter . '" is not accepted in pseudonyms');
                 }
             }
             if ($value === '') {
                 $value = null;
             }
             break;
         case 'email':
             if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
                 $this->errors[$columnName][] = _('This is not a valid email address');
             }
             break;
         case 'password':
             Ini::setIniFileName(Ini::INI_CONF_FILE);
             $minPasswordLength = Ini::getParam('User', 'minPasswordLength');
             if ($length < $minPasswordLength) {
                 $this->errors[$columnName][] = _('The password length must be at least ' . $minPasswordLength);
             }
             $value = crypt($value, Ini::getParam('User', 'passwordCryptSalt'));
             break;
     }
     if (count($this->errors[$columnName]) === 0) {
         unset($this->errors[$columnName]);
     }
     return $value;
 }
<?php

/**
 * Launch a websocket server instance
 *
 * @package    Launcher
 * @author     Romain Laneuville <*****@*****.**>
 */
use classes\IniManager as Ini;
use classes\ThrowableManager;
use classes\websocket\ServerRequestHandler;
use Icicle\WebSocket\Server\Server;
use Icicle\Loop;
require_once 'autoloader.php';
try {
    $params = Ini::getSectionParams('Socket');
    $server = new Server(new ServerRequestHandler());
    $server->listen($params['port'], $params['address']);
    Loop\run();
} catch (\Throwable $t) {
    $throwableManager = new ThrowableManager();
    $throwableManager->log($t);
} finally {
    exit(0);
}
 /**
  * Constructor that instantiate a new logger
  */
 public function __construct()
 {
     Ini::setIniFileName('conf.ini');
     $this->logger = new Logger(Ini::getParam('Exception', 'implementedLogger'));
 }
Beispiel #16
0
 /**
  * Initialize Elasticsearch by creating index, mapping and aliases from the conf.ini file
  */
 private function initElasticsearch()
 {
     $conf = Ini::getSectionParams('ElasticSearch');
     // Create index
     $this->createElasticsearchIndex($conf['index'], (int) $conf['version'], (int) $conf['numberOfShards'], (int) $conf['numberOfReplicas']);
     // Create mapping
     $this->createElasticsearchMapping($conf['index'], (int) $conf['version'], 'message', static::$ES_CHAT_MAPPING);
     // Bind aliases
     $this->bindAliasesToIndex($conf['index'] . '_v' . $conf['version'], $conf['index']);
     // Generate data
     $this->generateEsData($conf['index']);
 }
Beispiel #17
0
        ============================-->

        <?php 
WebContentInclude::includeDirectoryFiles(Ini::getParam('Web', 'pagesPath'));
?>

        <!--====  End of Pages  ====-->

        <!--============================
        =            Modals            =
        =============================-->

        <?php 
WebContentInclude::includeDirectoryFiles(Ini::getParam('Web', 'modalsPath'));
?>

        <!--====  End of Modals  ====-->

        <!--============================
        =            Alerts            =
        =============================-->

        <?php 
WebContentInclude::includeDirectoryFiles(Ini::getParam('Web', 'alertsPath'));
?>

        <!--====  End of Alerts  ====-->

    </body>
</html>
 /**
  * Constructor that instantiates a ConsoleColors
  */
 public function __construct()
 {
     static::$echoEncoding = Ini::getParam('Console', 'encoding');
 }
 /**
  * Constructor that loads chat parameters
  */
 public function __construct()
 {
     Ini::setIniFileName(Ini::INI_CONF_FILE);
     $conf = Ini::getSectionParams('Client service');
     $this->serviceName = $conf['serviceName'];
 }
 /**
  * Constructor that loads connection parameters
  *
  * @param      string[]  $parameters  OPTIONAL connection parameters
  * @param      bool      $verbose     OPTIONAL true if output should be print, false if not and null will load the
  *                                    ini value
  */
 public function __construct(array $parameters = null, bool $verbose = null)
 {
     $this->params = $parameters !== null ? $parameters : Ini::getSectionParams('Deployment');
     $this->verbose = (int) Ini::getParam('Deployment', 'verbose');
     $this->resource = null;
 }
Beispiel #21
0
 /**
  * Constructor
  */
 public function __construct()
 {
     static::$echoEncoding = Ini::getParam('Console', 'encoding');
     $this->maxLength = Ini::getParam('Console', 'maxLength');
 }