public function init() { Requirements::set_backend(new BetterRequirements_Backend()); parent::init(); Requirements::set_combined_files_folder(project() . '/_combinedfiles'); Requirements::set_force_js_to_bottom(true); $this->requireJS(); $this->requireCSS(); }
public function testRequirements() { $requirements = $this->getMock("Requirements_Backend", array("javascript", "css")); $jsFile = FRAMEWORK_DIR . '/tests/forms/a.js'; $cssFile = FRAMEWORK_DIR . '/tests/forms/a.js'; $requirements->expects($this->once())->method('javascript')->with($jsFile); $requirements->expects($this->once())->method('css')->with($cssFile); Requirements::set_backend($requirements); $template = $this->render("<% require javascript({$jsFile}) %>\n\t\t<% require css({$cssFile}) %>"); $this->assertFalse((bool) trim($template), "Should be no content in this return."); }
function testRequirements() { $requirements = $this->getMock("Requirements_Backend", array("javascript", "css")); $jsFile = 'sapphire/tests/forms/a.js'; $cssFile = 'sapphire/tests/forms/a.js'; $requirements->expects($this->once())->method('javascript')->with($jsFile); $requirements->expects($this->once())->method('css')->with($cssFile); Requirements::set_backend($requirements); $data = new ArrayData(array()); $viewer = SSViewer::fromString(<<<SS \t\t<% require javascript({$jsFile}) %> \t\t<% require css({$cssFile}) %> SS ); $template = $viewer->process($data); $this->assertFalse((bool) trim($template), "Should be no content in this return."); }
public function tearDown() { // Preserve memory settings ini_set('memory_limit', $this->originalMemoryLimit ? $this->originalMemoryLimit : -1); // Restore email configuration $this->originalMailer = null; $this->mailer = null; // Restore password validation if ($this->originalMemberPasswordValidator) { Member::set_password_validator($this->originalMemberPasswordValidator); } // Restore requirements if ($this->originalRequirements) { Requirements::set_backend($this->originalRequirements); } // Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls self::$is_running_test = $this->originalIsRunningTest; $this->originalIsRunningTest = null; // Reset mocked datetime DBDatetime::clear_mock_now(); // Stop the redirection that might have been requested in the test. // Note: Ideally a clean Controller should be created for each test. // Now all tests executed in a batch share the same controller. $controller = Controller::has_curr() ? Controller::curr() : null; if ($controller && $controller->response && $controller->response->getHeader('Location')) { $controller->response->setStatusCode(200); $controller->response->removeHeader('Location'); } Versioned::set_reading_mode($this->originalReadingMode); //unnest injector / config now that tests are over Injector::unnest(); Config::unnest(); }
public function testProcessOnlyIncludesRequirementsOnce() { $template = new SSViewer(array('SSViewerTestProcess')); $basePath = dirname($this->getCurrentRelativePath()) . '/forms'; $backend = new Requirements_Backend(); $backend->set_combined_files_enabled(false); $backend->combine_files('RequirementsTest_ab.css', array($basePath . '/RequirementsTest_a.css', $basePath . '/RequirementsTest_b.css')); Requirements::set_backend($backend); $this->assertEquals(1, substr_count($template->process(array()), "a.css")); $this->assertEquals(1, substr_count($template->process(array()), "b.css")); // if we disable the requirements then we should get nothing $template->includeRequirements(false); $this->assertEquals(0, substr_count($template->process(array()), "a.css")); $this->assertEquals(0, substr_count($template->process(array()), "b.css")); }
public function testConditionalTemplateRequire() { $basePath = $this->getCurrentRelativePath(); // we're asserting "framework", so set the relative path accordingly in case FRAMEWORK_DIR was changed // to something else $basePath = 'framework' . substr($basePath, strlen(FRAMEWORK_DIR)); $backend = new Requirements_Backend(); $holder = Requirements::backend(); Requirements::set_backend($backend); $data = new ArrayData(array('FailTest' => true)); $data->renderWith('RequirementsTest_Conditionals'); $this->assertFileIncluded($backend, 'css', $basePath . '/RequirementsTest_a.css'); $this->assertFileIncluded($backend, 'js', array($basePath . '/RequirementsTest_b.js', $basePath . '/RequirementsTest_c.js')); $this->assertFileNotIncluded($backend, 'js', $basePath . '/RequirementsTest_a.js'); $this->assertFileNotIncluded($backend, 'css', array($basePath . '/RequirementsTest_b.css', $basePath . '/RequirementsTest_c.css')); $backend->clear(); $data = new ArrayData(array('FailTest' => false)); $data->renderWith('RequirementsTest_Conditionals'); $this->assertFileNotIncluded($backend, 'css', $basePath . '/RequirementsTest_a.css'); $this->assertFileNotIncluded($backend, 'js', array($basePath . '/RequirementsTest_b.js', $basePath . '/RequirementsTest_c.js')); $this->assertFileIncluded($backend, 'js', $basePath . '/RequirementsTest_a.js'); $this->assertFileIncluded($backend, 'css', array($basePath . '/RequirementsTest_b.css', $basePath . '/RequirementsTest_c.css')); Requirements::set_backend($holder); }
/** * Load all the template variables into the internal variables, including * the template into body. Called before send() or debugSend() * $isPlain=true will cause the template to be ignored, otherwise the GenericEmail template will be used * and it won't be plain email :) * * This function is updated to rewrite urls in a safely manner and inline css. * It will also changed the requirements backend to avoid requiring stuff in the html. */ protected function parseVariables($isPlain = false) { $origState = Config::inst()->get('SSViewer', 'source_file_comments'); Config::inst()->update('SSViewer', 'source_file_comments', false); // Workaround to avoid clutter in our rendered html $backend = Requirements::backend(); Requirements::set_backend(new MandrillRequirementsBackend()); if (!$this->parseVariables_done) { $this->parseVariables_done = true; if (!$this->original_body) { $this->original_body = $this->body; } // Parse $ variables in the base parameters $data = $this->templateData(); // Process a .SS template file $fullBody = $this->original_body; if ($this->parse_body) { try { $viewer = new SSViewer_FromString($fullBody); $fullBody = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } // Also parse the email title try { $viewer = new SSViewer_FromString($this->subject); $this->subject = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } if ($this->callout) { try { $viewer = new SSViewer_FromString($this->callout); $this->callout = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } } if ($this->sidebar) { try { $viewer = new SSViewer_FromString($this->sidebar); $this->sidebar = $viewer->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } } } if ($this->ss_template && !$isPlain) { // Requery data so that updated versions of To, From, Subject, etc are included $data = $this->templateData(); $template = new SSViewer($this->ss_template); if ($template->exists()) { // Make sure we included the parsed body into layout $data->setField('Body', $fullBody); try { $fullBody = $template->process($data); } catch (Exception $ex) { SS_Log::log($ex->getMessage(), SS_Log::DEBUG); } } } // Rewrite relative URLs $this->body = self::rewriteURLs($fullBody); } Config::inst()->update('SSViewer', 'source_file_comments', $origState); Requirements::set_backend($backend); return $this; }
<?php Requirements::set_backend(Injector::inst()->get("SectionedHeadJsBackend"));
/** * Test a URL request, returning a response object. * * This method is the counterpart of Director::direct() that is used in functional testing. It will execute the URL given, * * @param string $url The URL to visit * @param array $postVars The $_POST & $_FILES variables * @param Session $session The {@link Session} object representing the current session. By passing the same object to multiple * calls of Director::test(), you can simulate a persisted session. * @param string $httpMethod The HTTP method, such as GET or POST. It will default to POST if postVars is set, GET otherwise. * Overwritten by $postVars['_method'] if present. * @param string $body The HTTP body * @param array $headers HTTP headers with key-value pairs * @param array $cookies to populate $_COOKIE * @return SS_HTTPResponse * * @uses getControllerForURL() The rule-lookup logic is handled by this. * @uses Controller::run() Controller::run() handles the page logic for a Director::direct() call. */ static function test($url, $postVars = null, $session = null, $httpMethod = null, $body = null, $headers = null, $cookies = null) { // These are needed so that calling Director::test() doesnt muck with whoever is calling it. // Really, it's some inappropriate coupling and should be resolved by making less use of statics $oldStage = Versioned::current_stage(); $getVars = array(); if (!$httpMethod) { $httpMethod = $postVars || is_array($postVars) ? "POST" : "GET"; } if (!$session) { $session = new Session(null); } // Back up the current values of the superglobals $existingRequestVars = isset($_REQUEST) ? $_REQUEST : array(); $existingGetVars = isset($_GET) ? $_GET : array(); $existingPostVars = isset($_POST) ? $_POST : array(); $existingSessionVars = isset($_SESSION) ? $_SESSION : array(); $existingCookies = isset($_COOKIE) ? $_COOKIE : array(); $existingServer = isset($_SERVER) ? $_SERVER : array(); $existingCookieReportErrors = Cookie::report_errors(); $existingRequirementsBackend = Requirements::backend(); Cookie::set_report_errors(false); Requirements::set_backend(new Requirements_Backend()); // Handle absolute URLs if (@parse_url($url, PHP_URL_HOST) != '') { $bits = parse_url($url); $_SERVER['HTTP_HOST'] = $bits['host']; $url = Director::makeRelative($url); } $urlWithQuerystring = $url; if (strpos($url, '?') !== false) { list($url, $getVarsEncoded) = explode('?', $url, 2); parse_str($getVarsEncoded, $getVars); } // Replace the superglobals with appropriate test values $_REQUEST = array_merge((array) $getVars, (array) $postVars); $_GET = (array) $getVars; $_POST = (array) $postVars; $_SESSION = $session ? $session->inst_getAll() : array(); $_COOKIE = (array) $cookies; $_SERVER['REQUEST_URI'] = Director::baseURL() . $urlWithQuerystring; $req = new SS_HTTPRequest($httpMethod, $url, $getVars, $postVars, $body); if ($headers) { foreach ($headers as $k => $v) { $req->addHeader($k, $v); } } $result = Director::handleRequest($req, $session); // Restore the superglobals $_REQUEST = $existingRequestVars; $_GET = $existingGetVars; $_POST = $existingPostVars; $_SESSION = $existingSessionVars; $_COOKIE = $existingCookies; $_SERVER = $existingServer; Cookie::set_report_errors($existingCookieReportErrors); Requirements::set_backend($existingRequirementsBackend); // These are needed so that calling Director::test() doesnt muck with whoever is calling it. // Really, it's some inappropriate coupling and should be resolved by making less use of statics Versioned::reading_stage($oldStage); return $result; }
<?php Requirements::set_backend(new ModuleRequirements_Backend());
<?php Requirements::set_backend(new SSGuru_Requirements_Backend()); define('SS_GDM_EXTENSIONS_DIR', basename(dirname(__FILE__))); Deprecation::notification_version("0.1.3", SS_GDM_EXTENSIONS_DIR);
function tearDown() { // Restore email configuration Email::set_mailer($this->originalMailer); $this->originalMailer = null; $this->mailer = null; // Restore password validation Member::set_password_validator($this->originalMemberPasswordValidator); // Restore requirements Requirements::set_backend($this->originalRequirements); // Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls self::$is_running_test = $this->originalIsRunningTest; $this->originalIsRunningTest = null; }
public function onBeforeInit() { Requirements::set_backend(new BetterRequirementsVersioning_Backend()); }
/** * Test a URL request, returning a response object. * * This method is the counterpart of Director::direct() that is used in functional testing. It will execute the * URL given, and return the result as an SS_HTTPResponse object. * * @param string $url The URL to visit * @param array $postVars The $_POST & $_FILES variables * @param Session $session The {@link Session} object representing the current session. By passing the same * object to multiple calls of Director::test(), you can simulate a persisted session. * @param string $httpMethod The HTTP method, such as GET or POST. It will default to POST if postVars is set, * GET otherwise. Overwritten by $postVars['_method'] if present. * @param string $body The HTTP body * @param array $headers HTTP headers with key-value pairs * @param array $cookies to populate $_COOKIE * @param HTTP_Request $request The {@see HTTP_Request} object generated as a part of this request * @return SS_HTTPResponse * * @uses getControllerForURL() The rule-lookup logic is handled by this. * @uses Controller::run() Controller::run() handles the page logic for a Director::direct() call. */ public static function test($url, $postVars = null, $session = null, $httpMethod = null, $body = null, $headers = null, $cookies = null, &$request = null) { Config::nest(); // These are needed so that calling Director::test() doesnt muck with whoever is calling it. // Really, it's some inappropriate coupling and should be resolved by making less use of statics $oldStage = Versioned::current_stage(); $getVars = array(); if (!$httpMethod) { $httpMethod = $postVars || is_array($postVars) ? "POST" : "GET"; } if (!$session) { $session = new Session(null); } // Back up the current values of the superglobals $existingRequestVars = isset($_REQUEST) ? $_REQUEST : array(); $existingGetVars = isset($_GET) ? $_GET : array(); $existingPostVars = isset($_POST) ? $_POST : array(); $existingSessionVars = isset($_SESSION) ? $_SESSION : array(); $existingCookies = isset($_COOKIE) ? $_COOKIE : array(); $existingServer = isset($_SERVER) ? $_SERVER : array(); $existingRequirementsBackend = Requirements::backend(); Config::inst()->update('Cookie', 'report_errors', false); Requirements::set_backend(new Requirements_Backend()); // Handle absolute URLs if (@parse_url($url, PHP_URL_HOST) != '') { $bits = parse_url($url); $_SERVER['HTTP_HOST'] = $bits['host']; $url = Director::makeRelative($url); } $urlWithQuerystring = $url; if (strpos($url, '?') !== false) { list($url, $getVarsEncoded) = explode('?', $url, 2); parse_str($getVarsEncoded, $getVars); } // Replace the superglobals with appropriate test values $_REQUEST = ArrayLib::array_merge_recursive((array) $getVars, (array) $postVars); $_GET = (array) $getVars; $_POST = (array) $postVars; $_SESSION = $session ? $session->inst_getAll() : array(); $_COOKIE = (array) $cookies; $_SERVER['REQUEST_URI'] = Director::baseURL() . $urlWithQuerystring; $request = new SS_HTTPRequest($httpMethod, $url, $getVars, $postVars, $body); if ($headers) { foreach ($headers as $k => $v) { $request->addHeader($k, $v); } } // Pre-request filtering // @see issue #2517 $model = DataModel::inst(); $output = Injector::inst()->get('RequestProcessor')->preRequest($request, $session, $model); if ($output === false) { // @TODO Need to NOT proceed with the request in an elegant manner throw new SS_HTTPResponse_Exception(_t('Director.INVALID_REQUEST', 'Invalid request'), 400); } // TODO: Pass in the DataModel $result = Director::handleRequest($request, $session, $model); // Ensure that the result is an SS_HTTPResponse object if (is_string($result)) { if (substr($result, 0, 9) == 'redirect:') { $response = new SS_HTTPResponse(); $response->redirect(substr($result, 9)); $result = $response; } else { $result = new SS_HTTPResponse($result); } } $output = Injector::inst()->get('RequestProcessor')->postRequest($request, $result, $model); if ($output === false) { throw new SS_HTTPResponse_Exception("Invalid response"); } // Restore the superglobals $_REQUEST = $existingRequestVars; $_GET = $existingGetVars; $_POST = $existingPostVars; $_SESSION = $existingSessionVars; $_COOKIE = $existingCookies; $_SERVER = $existingServer; Requirements::set_backend($existingRequirementsBackend); // These are needed so that calling Director::test() doesnt muck with whoever is calling it. // Really, it's some inappropriate coupling and should be resolved by making less use of statics Versioned::reading_stage($oldStage); Config::unnest(); return $result; }
<?php if (Director::isLive()) { Controller::add_extension('SS_MinifiedResponseExtension'); Requirements::set_backend(new Minify_Requirements_Backend()); if (defined('MINIFY_CACHE_BACKEND') && defined('MINIFY_CACHE_LIFETIME')) { $backend = unserialize(MINIFY_CACHE_BACKEND); SS_Cache::add_backend('MINIFY_CACHE_BACKEND', $backend['Type'], $backend['Options']); SS_Cache::set_cache_lifetime('MINIFY_CACHE_BACKEND', MINIFY_CACHE_LIFETIME, 100); SS_Cache::pick_backend('MINIFY_CACHE_BACKEND', 'MINIFY_CACHE', 100); } }
function testConditionalTemplateRequire() { $backend = new RequirementsTest_Backend(); $holder = Requirements::backend(); Requirements::set_backend($backend); $data = new ArrayData(array('FailTest' => true)); $data->renderWith('RequirementsTest_Conditionals'); $backend->assertFileIncluded('css', 'sapphire/tests/forms/RequirementsTest_a.css'); $backend->assertFileIncluded('js', array('sapphire/tests/forms/RequirementsTest_b.js', 'sapphire/tests/forms/RequirementsTest_c.js')); $backend->assertFileNotIncluded('js', 'sapphire/tests/forms/RequirementsTest_a.js'); $backend->assertFileNotIncluded('css', array('sapphire/tests/forms/RequirementsTest_b.css', 'sapphire/tests/forms/RequirementsTest_c.css')); $backend->clear(); $data = new ArrayData(array('FailTest' => false)); $data->renderWith('RequirementsTest_Conditionals'); $backend->assertFileNotIncluded('css', 'sapphire/tests/forms/RequirementsTest_a.css'); $backend->assertFileNotIncluded('js', array('sapphire/tests/forms/RequirementsTest_b.js', 'sapphire/tests/forms/RequirementsTest_c.js')); $backend->assertFileIncluded('js', 'sapphire/tests/forms/RequirementsTest_a.js'); $backend->assertFileIncluded('css', array('sapphire/tests/forms/RequirementsTest_b.css', 'sapphire/tests/forms/RequirementsTest_c.css')); Requirements::set_backend($holder); }
function tearDown() { // Preserve memory settings ini_set('memory_limit', $this->originalMemoryLimit ? $this->originalMemoryLimit : -1); // Restore email configuration Email::set_mailer($this->originalMailer); $this->originalMailer = null; $this->mailer = null; // Restore password validation Member::set_password_validator($this->originalMemberPasswordValidator); // Restore requirements Requirements::set_backend($this->originalRequirements); // Mark test as no longer being run - we use originalIsRunningTest to allow for nested SapphireTest calls self::$is_running_test = $this->originalIsRunningTest; $this->originalIsRunningTest = null; // Reset theme setting SSViewer::set_theme($this->originalTheme); // Reset mocked datetime SS_Datetime::clear_mock_now(); // Restore nested_urls state if ($this->originalNestedURLsState) { SiteTree::enable_nested_urls(); } else { SiteTree::disable_nested_urls(); } // Stop the redirection that might have been requested in the test. // Note: Ideally a clean Controller should be created for each test. // Now all tests executed in a batch share the same controller. $controller = Controller::has_curr() ? Controller::curr() : null; if ($controller && $controller->response && $controller->response->getHeader('Location')) { $controller->response->setStatusCode(200); $controller->response->removeHeader('Location'); } }
<?php Requirements::set_backend(new Milkyway\SS\Assets\RequirementsBackend());
<?php if (!defined('SS_MWM_DIR')) { define('SS_MWM_DIR', basename(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR))); } Requirements::set_backend(new \Milkyway\SS\Core\RequirementsBackend()); // Register all shortcodes for use with injector and shortcodable module Milkyway\SS\Shortcodes\Extensions\ShortcodableController::register(); Deprecation::notification_version('0.2', 'mwm-utilities'); /** * Credit for following functions goes to taylorotwell (laravel/framework) * * @credit taylorotwell (laravel/framework) * @licence MIT */ if (!function_exists('with')) { /** * Return the given object. Useful for chaining. * * @param mixed $object * @return mixed */ function with($object) { return $object; } } if (!function_exists('array_set')) { /** * Set an array item to a given value using "dot" notation. *
<?php Requirements::set_backend(new LessCompiler());
function testConditionalTemplateRequire() { $basePath = $this->getCurrentRelativePath(); $backend = new RequirementsTest_Backend(); $holder = Requirements::backend(); Requirements::set_backend($backend); $data = new ArrayData(array('FailTest' => true)); $data->renderWith('RequirementsTest_Conditionals'); $backend->assertFileIncluded('css', $basePath . '/RequirementsTest_a.css'); $backend->assertFileIncluded('js', array($basePath . '/RequirementsTest_b.js', $basePath . '/RequirementsTest_c.js')); $backend->assertFileNotIncluded('js', $basePath . '/RequirementsTest_a.js'); $backend->assertFileNotIncluded('css', array($basePath . '/RequirementsTest_b.css', $basePath . '/RequirementsTest_c.css')); $backend->clear(); $data = new ArrayData(array('FailTest' => false)); $data->renderWith('RequirementsTest_Conditionals'); $backend->assertFileNotIncluded('css', $basePath . '/RequirementsTest_a.css'); $backend->assertFileNotIncluded('js', array($basePath . '/RequirementsTest_b.js', $basePath . '/RequirementsTest_c.js')); $backend->assertFileIncluded('js', $basePath . '/RequirementsTest_a.js'); $backend->assertFileIncluded('css', array($basePath . '/RequirementsTest_b.css', $basePath . '/RequirementsTest_c.css')); Requirements::set_backend($holder); }
/** * Test a URL request, returning a response object. This method is the counterpart of * Director::direct() that is used in functional testing. It will execute the URL given, and * return the result as an SS_HTTPResponse object. * * @uses getControllerForURL() The rule-lookup logic is handled by this. * @uses Controller::run() Handles the page logic for a Director::direct() call. * * @param string $url The URL to visit. * @param array $postVars The $_POST & $_FILES variables. * @param array|Session $session The {@link Session} object representing the current session. * By passing the same object to multiple calls of Director::test(), you can simulate a persisted * session. * @param string $httpMethod The HTTP method, such as GET or POST. It will default to POST if * postVars is set, GET otherwise. Overwritten by $postVars['_method'] if present. * @param string $body The HTTP body. * @param array $headers HTTP headers with key-value pairs. * @param array|Cookie_Backend $cookies to populate $_COOKIE. * @param HTTP_Request $request The {@see HTTP_Request} object generated as a part of this request. * * @return SS_HTTPResponse * * @throws SS_HTTPResponse_Exception */ public static function test($url, $postVars = null, $session = array(), $httpMethod = null, $body = null, $headers = array(), $cookies = array(), &$request = null) { Config::nest(); Injector::nest(); // These are needed so that calling Director::test() does not muck with whoever is calling it. // Really, it's some inappropriate coupling and should be resolved by making less use of statics. $oldReadingMode = Versioned::get_reading_mode(); $getVars = array(); if (!$httpMethod) { $httpMethod = $postVars || is_array($postVars) ? "POST" : "GET"; } if (!$session) { $session = Injector::inst()->create('Session', array()); } $cookieJar = $cookies instanceof Cookie_Backend ? $cookies : Injector::inst()->createWithArgs('Cookie_Backend', array($cookies ?: array())); // Back up the current values of the superglobals $existingRequestVars = isset($_REQUEST) ? $_REQUEST : array(); $existingGetVars = isset($_GET) ? $_GET : array(); $existingPostVars = isset($_POST) ? $_POST : array(); $existingSessionVars = isset($_SESSION) ? $_SESSION : array(); $existingCookies = isset($_COOKIE) ? $_COOKIE : array(); $existingServer = isset($_SERVER) ? $_SERVER : array(); $existingRequirementsBackend = Requirements::backend(); Config::inst()->update('Cookie', 'report_errors', false); Requirements::set_backend(Injector::inst()->create('Requirements_Backend')); // Set callback to invoke prior to return $onCleanup = function () use($existingRequestVars, $existingGetVars, $existingPostVars, $existingSessionVars, $existingCookies, $existingServer, $existingRequirementsBackend, $oldReadingMode) { // Restore the super globals $_REQUEST = $existingRequestVars; $_GET = $existingGetVars; $_POST = $existingPostVars; $_SESSION = $existingSessionVars; $_COOKIE = $existingCookies; $_SERVER = $existingServer; Requirements::set_backend($existingRequirementsBackend); // These are needed so that calling Director::test() does not muck with whoever is calling it. // Really, it's some inappropriate coupling and should be resolved by making less use of statics Versioned::set_reading_mode($oldReadingMode); Injector::unnest(); // Restore old CookieJar, etc Config::unnest(); }; if (strpos($url, '#') !== false) { $url = substr($url, 0, strpos($url, '#')); } // Handle absolute URLs if (parse_url($url, PHP_URL_HOST)) { $bits = parse_url($url); // If a port is mentioned in the absolute URL, be sure to add that into the HTTP host if (isset($bits['port'])) { $_SERVER['HTTP_HOST'] = $bits['host'] . ':' . $bits['port']; } else { $_SERVER['HTTP_HOST'] = $bits['host']; } } // Ensure URL is properly made relative. // Example: url passed is "/ss31/my-page" (prefixed with BASE_URL), this should be changed to "my-page" $url = self::makeRelative($url); $urlWithQuerystring = $url; if (strpos($url, '?') !== false) { list($url, $getVarsEncoded) = explode('?', $url, 2); parse_str($getVarsEncoded, $getVars); } // Replace the super globals with appropriate test values $_REQUEST = ArrayLib::array_merge_recursive((array) $getVars, (array) $postVars); $_GET = (array) $getVars; $_POST = (array) $postVars; $_SESSION = $session ? $session->inst_getAll() : array(); $_COOKIE = $cookieJar->getAll(false); Injector::inst()->registerService($cookieJar, 'Cookie_Backend'); $_SERVER['REQUEST_URI'] = Director::baseURL() . $urlWithQuerystring; $request = new SS_HTTPRequest($httpMethod, $url, $getVars, $postVars, $body); if ($headers) { foreach ($headers as $k => $v) { $request->addHeader($k, $v); } } // Pre-request filtering // @see issue #2517 $model = DataModel::inst(); $output = Injector::inst()->get('RequestProcessor')->preRequest($request, $session, $model); if ($output === false) { $onCleanup(); throw new SS_HTTPResponse_Exception(_t('Director.INVALID_REQUEST', 'Invalid request'), 400); } // TODO: Pass in the DataModel $result = Director::handleRequest($request, $session, $model); // Ensure that the result is an SS_HTTPResponse object if (is_string($result)) { if (substr($result, 0, 9) == 'redirect:') { $response = new SS_HTTPResponse(); $response->redirect(substr($result, 9)); $result = $response; } else { $result = new SS_HTTPResponse($result); } } $output = Injector::inst()->get('RequestProcessor')->postRequest($request, $result, $model); if ($output === false) { $onCleanup(); throw new SS_HTTPResponse_Exception("Invalid response"); } // Return valid response $onCleanup(); return $result; }
<?php Requirements::set_backend(new Prefix_Requirements_Backend());