Skip to content

Commit

Permalink
Beta release
Browse files Browse the repository at this point in the history
Converted engine.php to Tina4Php object so configs can be specified before initializing load
  • Loading branch information
andrevanzuydam committed Jul 28, 2019
1 parent 9528d24 commit 3753e12
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 119 deletions.
112 changes: 112 additions & 0 deletions Tina4Php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* Created by PhpStorm.
* User: andrevanzuydam
* Date: 2019-07-28
* Time: 10:34
*/
namespace Tina4;

use Phpfastcache\CacheManager;
use Phpfastcache\Config\ConfigurationOption;
use Tina4\Routing;

class Tina4Php
{
private $DBA;
private $documentRoot; //The place where Tina4 exists
private $webRoot; //The place where the website exists


function __construct($config=null)
{
//root of the website
$this->documentRoot = realpath(dirname(__FILE__)."/../../../");
if (file_exists("Tina4.php")) {
$this->documentRoot = realpath(dirname(__FILE__));
}
error_log ("TINA4: document root ".$this->documentRoot);

//root of tina4
$this->webRoot = realpath(dirname(__FILE__));

error_log ("TINA4: web root ".$this->webRoot);

//check for composer defines
if (file_exists($this->webRoot."/vendor/autoload.php")) {
require_once $this->webRoot."/vendor/autoload.php";
}

if (file_exists($this->documentRoot."/vendor/autoload.php")) {
require_once $this->documentRoot."/vendor/autoload.php";
}



//system defines, perhaps can be defined or overridden by a config.php file.
if (file_exists("{$this->documentRoot}/config.php")) {
require_once ($this->documentRoot."/config.php");
}

if (!defined("TINA4_DEBUG")) {
define ("TINA4_DEBUG", false);
} else {
if (TINA4_DEBUG) {
error_log("TINA4 DEBUG: ON");
}
}

if(!defined("TINA4_TEMPLATE_LOCATIONS")) {
define("TINA4_TEMPLATE_LOCATIONS" , ["templates", "assets", "templates/snippets"]);
}

if(!defined("TINA4_ROUTE_LOCATIONS")) {
define("TINA4_ROUTE_LOCATIONS" , ["api","routes"]);
}

if(!defined("TINA4_INCLUDE_LOCATIONS")) {
define("TINA4_INCLUDE_LOCATIONS" , ["app","objects"]);
}

if (!defined( "TINA4_ALLOW_ORIGINS")) {
define("TINA4_ALLOW_ORIGINS", ["*"]);
}

//Setup caching options
$TINA4_CACHE_CONFIG =
new ConfigurationOption([
"path" => $this->documentRoot."/cache"
]);

/**
* Global array to store the routes that are declared during runtime
*/
global $arrRoutes;
$arrRoutes = [];

//Check if assets folder is there
if (!file_exists($this->documentRoot."/assets") && !file_exists("Tina4.php")) {
Tina4\Routing::recurseCopy($this->webRoot."/assets", $this->documentRoot."/assets");
}

//Add the .htaccess file for redirecting things
if (!file_exists($this->documentRoot."/.htaccess") && !file_exists("engine.php")) {
copy($this->webRoot."/.htaccess", $this->documentRoot."/.htaccess");
}


global $cache;

CacheManager::setDefaultConfig($TINA4_CACHE_CONFIG);

$cache = CacheManager::getInstance("files");


if (isset($_SERVER["REQUEST_URI"]) && isset($_SERVER["REQUEST_METHOD"])) {
return new Routing($this->documentRoot, $_SERVER["REQUEST_URI"], $_SERVER["REQUEST_METHOD"]);
} else {
return new Routing($this->documentRoot, "/", "GET");
}

}
}
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@
"phpfastcache/phpfastcache": "^7.0",
"coyl/git": "^0.1.7",
"codeception/codeception": "^2.5"
},
"autoload": {
"classmap": [
"Tina4Php.php",
"Tina4"
],
"psr-4": {
"Tina4\\":"Tina4/"
}
}
}
119 changes: 0 additions & 119 deletions engine.php

This file was deleted.

0 comments on commit 3753e12

Please sign in to comment.