Example #1
0
 function testConfig()
 {
     $path = \Alo::loadConfig('router', true);
     require $path;
     /** @var string $errorControllerClass */
     /** @var string $defaultController */
     /** @var array $routes */
     $this->assertTrue(isset($errorControllerClass), '$error_controller_class not set');
     $this->assertTrue(isset($defaultController), '$default_controller not set');
     $this->assertTrue(isset($routes), '$routes not set');
 }
Example #2
0
     *
     * @link   http://php.net/manual/en/function.trigger-error.php
     * @return bool
     */
    function phpNotice($msg)
    {
        return trigger_error($msg, E_USER_NOTICE);
    }
    /**
     * Triggers a PHP-level error with the level E_USER_DEPRECATED
     *
     * @author Art <*****@*****.**>
     *
     * @param string $msg Error message
     *
     * @link   http://php.net/manual/en/function.trigger-error.php
     * @return bool
     */
    function phpDeprecated($msg)
    {
        return trigger_error($msg, E_USER_DEPRECATED);
    }
    require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'alo.php';
    if (!defined('PHPUNIT_RUNNING')) {
        Alo::$router = new Alo\Controller\Router();
        Alo::includeonceifexists(DIR_APP . 'core' . DIRECTORY_SEPARATOR . 'autoload.php');
        Alo::$router->init();
    } else {
        Alo::includeonceifexists(DIR_APP . 'core' . DIRECTORY_SEPARATOR . 'autoload.php');
    }
}
Example #3
0
	DEFAULT CHARSET = `utf8mb4`;', 'TRUNCATE TABLE alo_locale;', 'TRUNCATE TABLE alo_session;', "INSERT INTO alo_locale(`lang`,`page`,`key`,`value`) VALUES\n('en','global','glob_one','one'),\n('en','global','glob_two','two'),\n('en','local','loc_three','three'),\n('en','local','loc_four','four'),\n('lt','local','loc_four','keturi')"];
/**
 * Global PHPUnit container class
 * @author Art <*****@*****.**>
 */
abstract class PhuGlobal
{
    /** @var Cron */
    static $cron;
    /** @var MemcachedWrapper */
    static $mcWrapper;
    /** @var RedisWrapper */
    static $redisWrapper;
    /** @var MySQL */
    static $mysql;
    /** @var Locale */
    static $locale;
}
if (!Alo::serverIsWindows()) {
    PhuGlobal::$cron = new Cron();
}
PhuGlobal::$mcWrapper = new MemcachedWrapper();
PhuGlobal::$redisWrapper = new RedisWrapper();
PhuGlobal::$mysql = new MySQL(ALO_MYSQL_SERVER, ALO_MYSQL_PORT, ALO_MYSQL_USER, ALO_MYSQL_PW, 'phpunit', ALO_MYSQL_CACHE);
foreach ($runThisSQL as $sql) {
    PhuGlobal::$mysql->prepQuery($sql);
}
PhuGlobal::$locale = new Locale(PhuGlobal::$mysql);
PhuGlobal::$locale->fetch(['local'], 'en', 'lt');
include_once 'tests/abstractcachetest.php';
include_once 'tests/abstractsessiontest.php';
Example #4
0
 /**
  * Instantiates the crontab handler
  *
  * @author Art <*****@*****.**>
  * @throws OS When the machine is running Windows
  */
 function __construct()
 {
     if (\Alo::serverIsWindows()) {
         throw new OS('Windows does not support cron!', OS::E_UNSUPPORTED);
     } else {
         $this->autocommit = false;
         $this->reloadCrontab();
     }
     self::$this =& $this;
 }
Example #5
0
<?php

namespace Alo\Cache;

use Redis;
if (!defined('GEN_START')) {
    http_response_code(404);
} else {
    \Alo::loadConfig('redis');
    /**
     * A wrapper for PHP's Redis extension.
     *
     * @author  Art <*****@*****.**>
     * @package Cache
     */
    class RedisWrapper extends AbstractCache
    {
        /**
         * The memcached instance
         *
         * @var Redis
         */
        protected $client;
        /**
         * Instantiates the class
         *
         * @author Art <*****@*****.**>
         *
         * @param boolean $initDefaultServer Whether to add a server on construct
         */
        function __construct($initDefaultServer = true)
Example #6
0
 /**
  * Initialises the routing variables
  *
  * @author Art <*****@*****.**>
  * @throws CE When the config file is not found
  * @throws CE When $error_controller_class is not present in the config file
  * @throws CE When The default controller is not present in the config file
  * @throws CE When $routes is not a valid array
  * @throws CE When a route value is not an array.
  * @return Router
  */
 protected function initRoutes()
 {
     $path = \Alo::loadConfig('router', true);
     if (!file_exists($path)) {
         throw new CE('Routing config file not found.', CE::E_CONFIG_NOT_FOUND);
     } else {
         require $path;
         if (!isset($errorControllerClass)) {
             throw new CE('Error controller class not found in config file.', CE::E_ERR_NOT_FOUND);
         } elseif (!isset($defaultController)) {
             throw new CE('$default_controller undefined in config file.', CE::E_DEFAULT_UNDEFINED);
         } elseif (!is_array(get($routes))) {
             throw new CE('The routes variable must be an associative array', CE::E_MALFORMED_ROUTES);
         } else {
             $this->errController = $errorControllerClass;
             $this->defaultController = $defaultController;
             foreach ($routes as $k => $v) {
                 if (is_array($v)) {
                     $this->routes[strtolower($k)] = array_merge(self::$routeDefaults, $v);
                 } else {
                     throw new CE('Route ' . $k . ' is not a valid array.', CE::E_MALFORMED_ROUTES);
                 }
             }
             \Log::debug('Routes initialised');
         }
     }
     return $this;
 }
<?php

namespace Alo\Cache;

use Memcache;
use Memcached;
if (!defined('GEN_START')) {
    http_response_code(404);
} else {
    \Alo::loadConfig('memcached');
    /**
     * A wrapper for PHP's Memcached extension. Will try to use the Memcached class
     * first, if it doesn't exist, will use Memcache.
     *
     * @author  Art <*****@*****.**>
     * @package Cache
     */
    class MemcachedWrapper extends AbstractCache
    {
        /**
         * Defines the class as Memcached
         *
         * @var int
         */
        const CLASS_MEMCACHED = 1;
        /**
         * Defines the class as Memcache
         *
         * @var int
         */
        const CLASS_MEMCACHE = 2;
Example #8
0
<?php

namespace Alo\Db;

use PDO;
if (!defined('GEN_START')) {
    http_response_code(404);
} else {
    \Alo::loadConfig('db' . DIRECTORY_SEPARATOR . 'mysql');
    /**
     * MySQL database manager
     *
     * @author Art <*****@*****.**>
     * @author Art <*****@*****.**>
     */
    class MySQL extends AbstractDb
    {
        /**
         * The PDO instance
         *
         * @var PDO
         */
        protected $pdo;
        /**
         * Instantiates the database connection
         *
         * @author Art <*****@*****.**>
         *
         * @param string $ip      The IP address to use
         * @param int    $port    The port to use
         * @param string $user    The username
Example #9
0
<?php

namespace Alo;

use PHPMailer;
if (!defined('GEN_START')) {
    http_response_code(404);
} else {
    require_once DIR_SYS . 'external' . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . 'class.phpmailer.php';
    require_once DIR_SYS . 'external' . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . 'PHPMailerAutoload.php';
    \Alo::loadConfig('email');
    /**
     * Mail wrapper for the external PHPMailer library
     *
     * @author Art <*****@*****.**>
     * @link   https://github.com/PHPMailer/PHPMailer
     */
    class Email extends PHPMailer
    {
        /**
         * Static reference to the last instance of the class
         *
         * @var Email
         */
        static $this;
        /**
         * Array of debug outputs, each send operation representing a key/value pair
         *
         * @var array
         */
        protected $debugOutput;