Skip to content

Commit

Permalink
Remove mcrypt dependency
Browse files Browse the repository at this point in the history
- Updates Slim 2.x to 2.6.2
- Fixes issue with query string
- Supports PHP 7.1.1
  • Loading branch information
wellingguzman committed Apr 26, 2017
1 parent 2d5dfc8 commit 7186776
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 64 deletions.
4 changes: 4 additions & 0 deletions api/core/Directus/Application/Application.php
Expand Up @@ -42,6 +42,10 @@ public function __construct(array $userSettings)
{
parent::__construct($userSettings);

$this->container->singleton('environment', function () {
return Environment::getInstance();
});

$this->container->singleton('response', function () {
return new BaseResponse();
});
Expand Down
74 changes: 74 additions & 0 deletions api/core/Directus/Application/Environment.php
@@ -0,0 +1,74 @@
<?php

/**
* Directus – <http://getdirectus.com>
*
* @link The canonical repository – <https://github.com/directus/directus>
* @copyright Copyright 2006-2017 RANGER Studio, LLC – <http://rangerstudio.com>
* @license GNU General Public License (v3) – <http://www.gnu.org/copyleft/gpl.html>
*/

namespace Directus\Application;

/**
* Application Environment variables
*
* This class was created to fix an issue in Slim 2.x
* the query string from the request differ from the query string in $_SERVER
* missing the run_api_router set in api/.htaccess
*
* @author Welling Guzmán <welling@rngr.org>
*/
class Environment extends \Slim\Environment
{
/**
* Gets the instance
*
* @param bool $refresh
*
* @return \Slim\Environment
*/
public static function getInstance($refresh = false)
{
$newInstance = false;
if (is_null(self::$environment) || $refresh) {
$newInstance = true;
}

$instance = parent::getInstance($refresh);

// ----------------------------------------------------------------------------
// Fix the path info
// ----------------------------------------------------------------------------
// When a new instance was created we re-created the PATH_INFO value
// By removing everything after "?" in the REQUEST_URI
// The query string is removed.
//
// Also we remove the physical path out of the REQUEST_URI
// ----------------------------------------------------------------------------
if ($newInstance) {
$requestUri = $_SERVER['REQUEST_URI'];
$scriptName = $_SERVER['SCRIPT_NAME'];

// Physical path
if (strpos($requestUri, $scriptName) !== false) {
// Without rewriting
$physicalPath = $scriptName;
} else {
// With rewriting
$physicalPath = str_replace('\\', '', dirname($scriptName));
}

// if Virtual path, starts with physical path
// Remove the physical path from request
if (substr($requestUri, 0, strlen($physicalPath)) == $physicalPath) {
$requestUri = substr($requestUri, strlen($physicalPath));
}

$instance['PATH_INFO'] = substr_replace($requestUri, '', strpos($requestUri, '?'));
}

return $instance;
}

}
4 changes: 2 additions & 2 deletions composer.json
@@ -1,8 +1,8 @@
{
"require": {
"php": ">=5.6.0",
"slim/slim": "2.3.2",
"slim/extras": "dev-develop",
"slim/slim": "2.6.2",
"slim/extras": "dev-master",
"twig/twig": "1.*",
"zendframework/zend-db": "dev-directus",
"directus/migrations": "dev-master",
Expand Down

0 comments on commit 7186776

Please sign in to comment.