Skip to content

Commit

Permalink
Merge 8c8c5c8 into fdaab73
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jan 18, 2021
2 parents fdaab73 + 8c8c5c8 commit afe3a86
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 126 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -20,7 +20,8 @@ require_once( 'twist/framework.php' );
...or with Composer

```php
use Twist\framework;
require __DIR__ . '/vendor/autoload.php';
\Twist\Classes\Framework::boot();
```

## Vagrant
Expand Down
127 changes: 127 additions & 0 deletions dist/twist/Classes/Framework.class.php
@@ -0,0 +1,127 @@
<?php

/**
* TwistPHP - An open source PHP MVC framework built from the ground up.
* Shadow Technologies Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Shadow Technologies Ltd. <contact@shadow-technologies.co.uk>
* @license https://www.gnu.org/licenses/gpl.html GPL License
* @link https://twistphp.com
*/

namespace Twist\Classes;

class Framework{

/**
* Temp function to allow the easy definition of core defines in preparation for Twist to be included
* @param $strKey
* @param $mxdValue
*/
protected static function define($strKey,$mxdValue){
if(!defined($strKey)){
define($strKey,$mxdValue);
}
}

public static function boot() {

if(!headers_sent() && (empty(getenv('twist_cron_child')) && empty(getenv('twist_cron')))){
//IE8 Session Fix
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
header('X-Frame-Options: SAMEORIGIN');

//Set the Twist Identifier
header('X-Powered-By: TwistPHP');

//Set twist session cookie
setcookie('twist_session',sha1(time().rand(1,9999)),time()+3600,'/');
}

error_reporting(E_ALL);
ini_set("display_errors", 1);

//Preset the timezone, once framework is up and running set from the settings table
date_default_timezone_set('Europe/London');
$_SERVER['TWIST_BOOT'] = microtime();

//Fix DOCUMENT_ROOT when running as Cron on some servers
if(!array_key_exists('DOCUMENT_ROOT',$_SERVER)){
$_SERVER['DOCUMENT_ROOT'] = TWIST_PUBLIC_ROOT;
}

//Fix SCRIPT_FILENAME when running as Cron on some servers
if(!array_key_exists('SCRIPT_FILENAME',$_SERVER)){
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
}

//If the SITE_URI_REWRITE is not already defined then it will be defined here
self::define('SITE_URI_REWRITE','/');

//TWIST_PUBLIC_ROOT - Can be defined in your index file
self::define('TWIST_PUBLIC_ROOT',$_SERVER['DOCUMENT_ROOT']);
self::define('TWIST_FRAMEWORK_ROOT',realpath(sprintf('%s/../../',dirname(__FILE__))).'/');

//TWIST_APP - Can be defined in your index file
self::define('TWIST_APP',sprintf('%s/app/',rtrim(TWIST_FRAMEWORK_ROOT,'/')));

require_once sprintf('%s/Autoload.class.php',dirname(__FILE__));
Autoload::init(realpath(sprintf('%s/../../',dirname(__FILE__))));

//Get the base location of the site, based on this config file (should be in the doc_root)
self::define('TWIST_FRAMEWORK',realpath(sprintf('%s/../',dirname(__FILE__))).'/');
self::define('TWIST_FRAMEWORK_CONFIG',sprintf('%sConfig/',TWIST_FRAMEWORK));
self::define('TWIST_FRAMEWORK_CLASSES',sprintf('%sClasses/',TWIST_FRAMEWORK));
self::define('TWIST_FRAMEWORK_DATA',sprintf('%sCore/Data/',TWIST_FRAMEWORK));
self::define('TWIST_FRAMEWORK_MODELS',sprintf('%sCore/Models/',TWIST_FRAMEWORK));
self::define('TWIST_FRAMEWORK_HELPERS',sprintf('%sCore/Helpers/',TWIST_FRAMEWORK));
self::define('TWIST_FRAMEWORK_VIEWS',sprintf('%sCore/Views/',TWIST_FRAMEWORK));
self::define('TWIST_FRAMEWORK_RESOURCES',sprintf('%sCore/Resources/',TWIST_FRAMEWORK));

self::define('TWIST_APP_AJAX',sprintf('%s/Ajax/',rtrim(TWIST_APP,'/')));
self::define('TWIST_APP_ASSETS',sprintf('%s/Assets/',rtrim(TWIST_APP,'/')));
self::define('TWIST_APP_CACHE',sprintf('%s/Cache/',rtrim(TWIST_APP,'/')));
self::define('TWIST_APP_CONFIG',sprintf('%s/Config/',rtrim(TWIST_APP,'/')));
self::define('TWIST_APP_CONTROLLERS',sprintf('%s/Controllers/',rtrim(TWIST_APP,'/')));
self::define('TWIST_APP_MODELS',sprintf('%s/Models/',rtrim(TWIST_APP,'/')));
self::define('TWIST_APP_VIEWS',sprintf('%s/Views/',rtrim(TWIST_APP,'/')));

//TWIST_PACKAGES - Can be defined in your index file
self::define('TWIST_PACKAGES',sprintf('%s/packages/',rtrim(TWIST_FRAMEWORK_ROOT,'/')));
self::define('TWIST_PACKAGE_INSTALL',sprintf('%s/packages/install/',rtrim(TWIST_FRAMEWORK_ROOT,'/')));

//TWIST_UPLOADS - Can be defined in your index file
self::define('TWIST_UPLOADS',sprintf('%s/uploads/',rtrim(TWIST_FRAMEWORK_ROOT,'/')));

/** From this point onwards you now have to use Twist::define() rather than self::define */
require_once sprintf('%sTwist.php',TWIST_FRAMEWORK);

//Define the version number of the TwistPHP installation
self::define('TWIST_VERSION',\Twist::version());

if(defined('TWIST_APP_CONFIG') && file_exists(sprintf('%sconfig.php',TWIST_APP_CONFIG))){
require_once sprintf('%sconfig.php',TWIST_APP_CONFIG);
}

//Include the config file
if(file_exists(sprintf('%s/../Config/default.php',dirname(__FILE__)))){
require_once sprintf('%s/../Config/default.php',dirname(__FILE__));
}

\Twist::launch();
\Twist::sheduledtasks();
}
}
113 changes: 0 additions & 113 deletions dist/twist/Core/boot.php

This file was deleted.

2 changes: 1 addition & 1 deletion dist/twist/Twist.php
Expand Up @@ -62,7 +62,7 @@ public static function version($strVersionPart = null){
$arrVersion = array(
'major' => 4,
'minor' => 0,
'patch' => 0,
'patch' => 2,
'pre-release' => ''//pre-release can be set to 'dev'
);

Expand Down
9 changes: 3 additions & 6 deletions dist/twist/framework.php
Expand Up @@ -22,10 +22,7 @@
* @link https://twistphp.com
*/

//Include the boot file
require_once sprintf('%s/Core/boot.php',dirname(__FILE__));
namespace Twist;

//Launch the framework ready for use
Twist::launch();

Twist::sheduledtasks();
require_once sprintf('%s/Classes/Framework.class.php',dirname(__FILE__));
\Twist\Classes\Framework::boot();
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "twistphp",
"version": "4.0.0",
"version": "4.0.2",
"description": "The PHP MVC framework with a TWIST",
"main": "",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions tests/Core/0-Boot/Boot.Test.php
Expand Up @@ -7,11 +7,10 @@ class Boot extends TestCase{
public function testLaunchFramework(){

//Include the boot file
require_once dirname(__FILE__).'/../../../dist/twist/Core/boot.php';
require_once dirname(__FILE__).'/../../../dist/twist/Classes/Framework.class.php';

//Launch the framework ready for use
Twist::launch();
Twist::sheduledtasks();
\Twist\Classes\Framework::boot();

$this->assertTrue(defined('TWIST_LAUNCHED'));
}
Expand Down

0 comments on commit afe3a86

Please sign in to comment.