Esempio n. 1
0
 public function putData($data)
 {
     $storage = TigerApp::getStorage();
     $this->filesize = strlen($data);
     $success = $storage->put($this->filename, $data);
     $this->save();
     return $success;
 }
Esempio n. 2
0
 public function testTigerSlimInvoke()
 {
     $body = implode("\n\n", $this->faker->paragraphs(5));
     TigerApp::run();
     $tigerApp = new TigerApp(__DIR__);
     $tigerSlim = $tigerApp->getSlimApp();
     $tigerSlim->get("/tigerslimtest", function () use($tigerSlim, $body) {
         $tigerSlim->response()->body($body);
     });
     $requestParams = array('PATH_INFO' => "/tigerslimtest", 'REQUEST_METHOD' => "GET");
     Environment::mock($requestParams);
     $response = $tigerSlim->invoke();
     $this->assertTrue($response instanceof Response);
     $this->assertEquals(200, $response->getStatus());
     $this->assertEquals($body, $response->getBody());
     $this->assertEquals(strlen($body), $response->getLength());
 }
Esempio n. 3
0
 public function logout()
 {
     $user = Models\User::getCurrent();
     if ($user instanceof Models\User) {
         TigerApp::log("Logout for {$user->username}");
     }
     Session::dispose('user');
     $this->slim->response()->redirect("/login");
 }
Esempio n. 4
0
 public function __construct()
 {
     parent::__construct();
     /**
      * @var TigerView $view
     */
     $view = $this->slim->view();
     $view->setSiteTitle(TigerApp::Config("Application Name"));
     $view->addCSS("vendor/twbs/bootstrap/dist/css/bootstrap.min.css");
     $view->addCSS("assets/css/navbar.css");
 }
Esempio n. 5
0
 /**
  * @param string $path
  * @return Response
  */
 protected function doRequest($method = "GET", $path = "/", $params = [])
 {
     $requestParams = array('PATH_INFO' => $path, 'REQUEST_METHOD' => $method);
     if ($method == "POST") {
         $requestParams['QUERY_STRING'] = http_build_query($params);
         $requestParams['slim.input'] = http_build_query($params);
     }
     Environment::mock($requestParams);
     $this->tiger = TigerApp::run();
     $this->slim = $this->tiger->getSlimApp();
     $response = $this->tiger->invoke();
     return $response;
 }
Esempio n. 6
0
 public function url($url)
 {
     // Do not process absolute URLs.
     if (strpos($url, '://') !== false) {
         return $url;
     }
     // Relative-to-root URLs...
     if (substr($url, 0, 1) == '/' && substr($url, 1, 1) != '/') {
         return $url;
     }
     // Remove excess slashes to the left of URL.
     for ($i = 0; $i <= 3; $i++) {
         $url = ltrim($url, "/");
     }
     $url = ltrim($url);
     return TigerApp::WebRoot() . $url;
 }
Esempio n. 7
0
 /**
  * @param $username
  * @param $password
  * @return bool
  */
 public function doLogin($username, $password)
 {
     // Support logging in with email address
     $user = Models\User::search()->where('email', $username)->execOne();
     // Support logging in with username
     if (!$user instanceof Models\User) {
         $user = Models\User::search()->where('username', $username)->execOne();
     }
     if (!$user instanceof Models\User) {
         TigerApp::log("No such user {$username}", Slim\Log::WARN);
         return false;
     } elseif ($user->checkPassword($password)) {
         Session::set("user", $user);
         return true;
     } else {
         TigerApp::log("Failed login for {$username}", Slim\Log::WARN);
         return false;
     }
 }
Esempio n. 8
0
 public function setUp()
 {
     $this->tiger = TigerApp::run();
     parent::setUp();
     $_SESSION = array();
     // Initialise Faker
     $this->faker = Faker\Factory::create();
     $this->faker->addProvider(new Faker\Provider\en_US\Person($this->faker));
     $this->faker->addProvider(new Faker\Provider\en_US\Address($this->faker));
     $this->faker->addProvider(new Faker\Provider\en_US\PhoneNumber($this->faker));
     $this->faker->addProvider(new Faker\Provider\en_US\Company($this->faker));
     $this->faker->addProvider(new Faker\Provider\Lorem($this->faker));
     $this->faker->addProvider(new Faker\Provider\Internet($this->faker));
     // Create Test user.
     $this->testUserUsername = $this->faker->userName;
     $this->testUserPassword = $this->faker->password;
     $this->testUser = new User();
     $this->testUser->username = $this->testUserUsername;
     $this->testUser->displayname = $this->faker->name();
     $this->testUser->email = $this->faker->safeEmail;
     $this->testUser->setPassword($this->testUserPassword);
     $this->testUser->save();
 }
Esempio n. 9
0
 public function save($automatic_reload = true)
 {
     if (!$this->user_uuid) {
         $this->user_uuid = UUID::v4();
     }
     if (!$this->user_id) {
         TigerApp::log("New user created: {$this->username} / {$this->displayname} / {$this->email}");
     }
     return parent::save($automatic_reload);
 }
Esempio n. 10
0
 /**
  * @return TigerApp
  */
 public function begin()
 {
     if (defined('APP_ENV')) {
         $configFile = APP_ENV . '.yaml';
     } elseif (getenv('HOST')) {
         $configFile = getenv('HOST') . '.yaml';
     } else {
         $configFile = 'Default.yaml';
     }
     $this->parseConfig("{$this->appRoot}/config/{$configFile}");
     $this->logger = $this->setupLogger();
     if ($this->config['Debug Mode'] == "On") {
         error_reporting(E_ALL);
         ini_set("display_errors", 1);
     }
     $environment = array_merge($_ENV, $_SERVER);
     ksort($environment);
     // TODO: Load app tree from yaml
     $this->appTree = self::$defaultAppTree;
     // Initialise databases
     if (count(TigerApp::Config("Databases")) > 0) {
         foreach (TigerApp::Config("Databases") as $name => $settings) {
             $config = array();
             $config['db_type'] = $settings['Type'];
             if (isset($settings['DockerLink'])) {
                 $prefix = strtoupper($settings['DockerLink']);
                 if (isset($environment["{$prefix}_PORT"])) {
                     $host = parse_url($environment["{$prefix}_PORT"]);
                     $config['db_hostname'] = $host['host'];
                     $config['db_port'] = $host['port'];
                     if (isset($environment["{$prefix}_USERNAME"])) {
                         $config['db_username'] = $environment["{$prefix}_USERNAME"];
                     }
                     if (isset($environment["{$prefix}_ENV_MYSQL_USER"])) {
                         $config['db_username'] = $environment["{$prefix}_ENV_MYSQL_USER"];
                     }
                     if (isset($environment["{$prefix}_PASSWORD"])) {
                         $config['db_password'] = $environment["{$prefix}_PASSWORD"];
                     }
                     if (isset($environment["{$prefix}_ENV_MYSQL_PASSWORD"])) {
                         $config['db_password'] = $environment["{$prefix}_ENV_MYSQL_PASSWORD"];
                     }
                     if (isset($environment["{$prefix}_DATABASE"])) {
                         $config['db_database'] = $environment["{$prefix}_DATABASE"];
                     }
                     if (isset($environment["{$prefix}_ENV_MYSQL_DATABASE"])) {
                         $config['db_database'] = $environment["{$prefix}_ENV_MYSQL_DATABASE"];
                     }
                 } else {
                     throw new \Exception("Cannot find \$environment[{$prefix}_PORT] trying to use DockerLink config.");
                 }
             }
             if (isset($settings['Host'])) {
                 $config['db_hostname'] = $settings['Host'];
             }
             if (isset($settings['Port'])) {
                 $config['db_port'] = $settings['Port'];
             }
             if (isset($settings['Username'])) {
                 $config['db_username'] = $settings['Username'];
             }
             if (isset($settings['Password'])) {
                 $config['db_password'] = $settings['Password'];
             }
             if (isset($settings['Database'])) {
                 $config['db_database'] = $settings['Database'];
             }
             // Sqlite-specific
             if (isset($settings['File'])) {
                 $config['db_file'] = $settings['File'];
             }
             $this->dbPool[$name] = new ActiveRecord\DatabaseLayer($config);
         }
     }
     // Initialise Storage Pool
     if (TigerApp::Config("Storage") !== false) {
         foreach (TigerApp::Config("Storage") as $name => $config) {
             $this->storagePool[$name] = $this->setupStorage($config);
         }
     }
     // Initialise Redis Pool
     // TODO: Write this.
     // Initialise Session
     $this->session = new Session();
     // Initialise slim app.
     $this->slimApp = new TigerSlim(array('templates.path' => self::TemplatesRoot(), 'log.writer' => $this->logger, 'log.enabled' => true));
     // Set up whoops
     //$this->slimApp->config('whoops.editor', 'phpstorm');
     //$this->slimApp->add(new WhoopsMiddleware());
     // Set the View controller.
     // TODO: Make this settable in the config or somewhere in the sample App
     $this->slimApp->view(new TigerView());
     // Add routes to slim
     $this->parseRoutes();
     return $this;
 }
Esempio n. 11
0
 public function setUp()
 {
     TigerApp::run();
     $this->tigerView = new TigerView();
     $this->rrmdir(TigerApp::AppRoot() . "/public/cache");
 }
Esempio n. 12
0
 public function __construct()
 {
     $this->slim = TigerApp::getSlimApp();
 }
Esempio n. 13
0
<?php

require_once "../bootstrap.php";
use TigerKit\TigerApp;
TigerApp::run()->execute();
Esempio n. 14
0
<?php

/** @var $app \Slim\Slim */
use SampleApp\Controllers;
# Index page.
\TigerKit\TigerApp::getSlimApp()->get('/', '\\SampleApp\\Controllers\\IndexController:index');
# User Auth
\TigerKit\TigerApp::getSlimApp()->get('/login', '\\SampleApp\\Controllers\\UserController:showLogin');
\TigerKit\TigerApp::getSlimApp()->post('/login', '\\SampleApp\\Controllers\\UserController:doLogin');
\TigerKit\TigerApp::getSlimApp()->get('/register', '\\SampleApp\\Controllers\\UserController:showRegister');
\TigerKit\TigerApp::getSlimApp()->post('/register', '\\SampleApp\\Controllers\\UserController:doRegister');
\TigerKit\TigerApp::getSlimApp()->get('/logout', '\\SampleApp\\Controllers\\UserController:logout');
# Dashboard
\TigerKit\TigerApp::getSlimApp()->get('/dashboard', '\\SampleApp\\Controllers\\DashboardController:dashboard');
# Gallery
\TigerKit\TigerApp::getSlimApp()->get('/gallery', '\\SampleApp\\Controllers\\GalleryController:showList');
\TigerKit\TigerApp::getSlimApp()->get('/gallery/upload', '\\SampleApp\\Controllers\\GalleryController:showUpload');
\TigerKit\TigerApp::getSlimApp()->post('/gallery/upload', '\\SampleApp\\Controllers\\GalleryController:doUpload');
# Boards
\TigerKit\TigerApp::getSlimApp()->get('/r', '\\SampleApp\\Controllers\\BoardController:showHomepage');
\TigerKit\TigerApp::getSlimApp()->get('/r/all', '\\SampleApp\\Controllers\\BoardController:showAll');
\TigerKit\TigerApp::getSlimApp()->get('/r/new', '\\SampleApp\\Controllers\\BoardController:showNew');
\TigerKit\TigerApp::getSlimApp()->get('/r/list', '\\SampleApp\\Controllers\\BoardController:listBoards');
\TigerKit\TigerApp::getSlimApp()->get('/r/:board', '\\SampleApp\\Controllers\\BoardController:showBoard');
\TigerKit\TigerApp::getSlimApp()->get('/r/:board/:thread', '\\SampleApp\\Controllers\\BoardController:showThread');
Esempio n. 15
0
 /**
  * @expectedException \TigerKit\TigerException
  * @expectedExceptionMessage Unsupported storage type: notatype.
  */
 public function testSetupStorageBogusType()
 {
     TigerApp::run()->begin()->setupStorage(['Type' => 'notatype']);
 }