當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SapphireTest::is_running_test方法代碼示例

本文整理匯總了PHP中SapphireTest::is_running_test方法的典型用法代碼示例。如果您正苦於以下問題:PHP SapphireTest::is_running_test方法的具體用法?PHP SapphireTest::is_running_test怎麽用?PHP SapphireTest::is_running_test使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SapphireTest的用法示例。


在下文中一共展示了SapphireTest::is_running_test方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: sendFile

 /**
  * Output file to the browser.
  * For performance reasons, we avoid SS_HTTPResponse and just output the contents instead.
  */
 public function sendFile($file)
 {
     $path = $file->getFullPath();
     if (SapphireTest::is_running_test()) {
         return file_get_contents($path);
     }
     header('Content-Description: File Transfer');
     // Quotes needed to retain spaces (http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download)
     header('Content-Disposition: inline; filename="' . basename($path) . '"');
     header('Content-Length: ' . $file->getAbsoluteSize());
     header('Content-Type: ' . HTTP::get_mime_type($file->getRelativePath()));
     header('Content-Transfer-Encoding: binary');
     // Fixes IE6,7,8 file downloads over HTTPS bug (http://support.microsoft.com/kb/812935)
     header('Pragma: ');
     if ($this->config()->min_download_bandwidth) {
         // Allow the download to last long enough to allow full download with min_download_bandwidth connection.
         increase_time_limit_to((int) (filesize($path) / ($this->config()->min_download_bandwidth * 1024)));
     } else {
         // Remove the timelimit.
         increase_time_limit_to(0);
     }
     // Clear PHP buffer, otherwise the script will try to allocate memory for entire file.
     while (ob_get_level() > 0) {
         ob_end_flush();
     }
     // Prevent blocking of the session file by PHP. Without this the user can't visit another page of the same
     // website during download (see http://konrness.com/php5/how-to-prevent-blocking-php-requests/)
     session_write_close();
     readfile($path);
     die;
 }
開發者ID:helpfulrobot,項目名稱:i-lateral-silverstripe-commerce-downloadableproduct,代碼行數:35,代碼來源:DownloadableFileController.php

示例2: sendFile

 /**
  * Output file to the browser.
  * For performance reasons, we avoid SS_HTTPResponse and just output the contents instead.
  */
 public function sendFile($file)
 {
     $reader = $file->reader();
     if (!$reader || !$reader->isReadable()) {
         return;
     }
     if (class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
         return $reader->read();
     }
     $type = HTTP::get_mime_type($file->Filename);
     $disposition = strpos($type, 'image') !== false ? 'inline' : 'attachment';
     header('Content-Description: File Transfer');
     // Quotes needed to retain spaces (http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download)
     header(sprintf('Content-Disposition: %s; filename="%s"', $disposition, basename($file->Filename)));
     header('Content-Length: ' . $file->FileSize);
     header('Content-Type: ' . $type);
     header('Content-Transfer-Encoding: binary');
     // Ensure we enforce no-cache headers consistently, so that files accesses aren't cached by CDN/edge networks
     header('Pragma: no-cache');
     header('Cache-Control: private, no-cache, no-store');
     increase_time_limit_to(0);
     // Clear PHP buffer, otherwise the script will try to allocate memory for entire file.
     while (ob_get_level() > 0) {
         ob_end_flush();
     }
     // Prevent blocking of the session file by PHP. Without this the user can't visit another page of the same
     // website during download (see http://konrness.com/php5/how-to-prevent-blocking-php-requests/)
     session_write_close();
     echo $reader->read();
     die;
 }
開發者ID:stephenmcm,項目名稱:silverstripe-cdncontent,代碼行數:35,代碼來源:CDNSecureFileController.php

示例3: validate

 /**
  * Run through the rules for this validator checking against
  * the temporary file set by {@link setTmpFile()} to see if
  * the file is deemed valid or not.
  * 
  * @return boolean
  */
 public function validate()
 {
     // we don't validate for empty upload fields yet
     if (!isset($this->tmpFile['name']) || empty($this->tmpFile['name'])) {
         return true;
     }
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     //needed to allow XHR uploads
     /*if(isset($this->tmpFile['tmp_name']) && !is_uploaded_file($this->tmpFile['tmp_name']) && !$isRunningTests) {
     			$this->errors[] = _t('File.NOVALIDUPLOAD', 'File is not a valid upload');
     			return false;
     		}*/
     $pathInfo = pathinfo($this->tmpFile['name']);
     // filesize validation
     if (!$this->isValidSize()) {
         $ext = isset($pathInfo['extension']) ? $pathInfo['extension'] : '';
         $arg = File::format_size($this->getAllowedMaxFileSize($ext));
         $this->errors[] = sprintf(_t('File.TOOLARGE', 'Filesize is too large, maximum %s allowed.', PR_MEDIUM, 'Argument 1: Filesize (e.g. 1MB)'), $arg);
         return false;
     }
     // extension validation
     if (!$this->isValidExtension()) {
         $this->errors[] = sprintf(_t('File.INVALIDEXTENSION', 'Extension is not allowed (valid: %s)', PR_MEDIUM, 'Argument 1: Comma-separated list of valid extensions'), wordwrap(implode(', ', $this->allowedExtensions)));
         return false;
     }
     return true;
 }
開發者ID:helpfulrobot,項目名稱:burnbright-silverstripe-ajaxuploadfield,代碼行數:34,代碼來源:XHRUpload.php

示例4: preRequest

 public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     // Bootstrap session so that Session::get() accesses the right instance
     $dummyController = new Controller();
     $dummyController->setSession($session);
     $dummyController->setRequest($request);
     $dummyController->pushCurrent();
     // Block non-authenticated users from setting the stage mode
     if (!Versioned::can_choose_site_stage($request)) {
         $permissionMessage = sprintf(_t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>'), Controller::join_links(Director::baseURL(), $request->getURL(), "?stage=Live"));
         // Force output since RequestFilter::preRequest doesn't support response overriding
         $response = Security::permissionFailure($dummyController, $permissionMessage);
         $session->inst_save();
         $dummyController->popCurrent();
         // Prevent output in testing
         if (class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
             throw new SS_HTTPResponse_Exception($response);
         }
         $response->output();
         die;
     }
     Versioned::choose_site_stage();
     $dummyController->popCurrent();
     return true;
 }
開發者ID:jacobbuck,項目名稱:silverstripe-framework,代碼行數:25,代碼來源:VersionedRequestFilter.php

示例5: __construct

 /**
  * Start a new instance of this class.
  * @param string $url The URL to parse for links
  */
 function __construct($url)
 {
     $this->url = $url;
     if (class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
         $this->showMessages = false;
     }
 }
開發者ID:halkyon,項目名稱:silverstripe-linkchecker,代碼行數:11,代碼來源:LinkCheckProcessor.php

示例6: init

 function init()
 {
     parent::init();
     $canAccess = Director::isDev() || Director::is_cli() && !SapphireTest::is_running_test() || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this);
     }
 }
開發者ID:SustainableCoastlines,項目名稱:loveyourwater,代碼行數:8,代碼來源:TaskRunner.php

示例7: init

 public function init()
 {
     parent::init();
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     $canAccess = Director::isDev() || Director::is_cli() && !$isRunningTests || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this);
     }
 }
開發者ID:ivoba,項目名稱:silverstripe-framework,代碼行數:9,代碼來源:TaskRunner.php

示例8: requireLogin

 /**
  * Require basic authentication.  Will request a username and password if none is given.
  *
  * Used by {@link Controller::init()}.
  *
  * @throws SS_HTTPResponse_Exception
  *
  * @param string $realm
  * @param string|array $permissionCode Optional
  * @param boolean $tryUsingSessionLogin If true, then the method with authenticate against the
  *  session log-in if those credentials are disabled.
  * @return Member $member
  */
 public static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true)
 {
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     if (!Security::database_is_ready() || Director::is_cli() && !$isRunningTests) {
         return true;
     }
     /*
      * Enable HTTP Basic authentication workaround for PHP running in CGI mode with Apache
      * Depending on server configuration the auth header may be in HTTP_AUTHORIZATION or
      * REDIRECT_HTTP_AUTHORIZATION
      *
      * The follow rewrite rule must be in the sites .htaccess file to enable this workaround
      * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
      */
     $authHeader = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) ? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] : null);
     $matches = array();
     if ($authHeader && preg_match('/Basic\\s+(.*)$/i', $authHeader, $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     $member = null;
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null);
     }
     if (!$member && $tryUsingSessionLogin) {
         $member = Member::currentUser();
     }
     // If we've failed the authentication mechanism, then show the login form
     if (!$member) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised"));
         } else {
             $response->setBody(_t('BasicAuth.ENTERINFO', "Please enter a username and password."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     return $member;
 }
開發者ID:XDdesigners,項目名稱:silverstripe-framework,代碼行數:68,代碼來源:BasicAuth.php

示例9: __construct

 /**
  * Register our shutdown handler
  */
 public function __construct()
 {
     // bind a shutdown function to process all 'immediate' queued jobs if needed, but only in CLI mode
     if (self::$use_shutdown_function && Director::is_cli()) {
         if (class_exists('PHPUnit_Framework_TestCase') && SapphireTest::is_running_test()) {
             // do NOTHING
         } else {
             register_shutdown_function(array($this, 'onShutdown'));
         }
     }
 }
開發者ID:nyeholt,項目名稱:silverstripe-queuedjobs,代碼行數:14,代碼來源:QueuedJobService.php

示例10: init

 function init()
 {
     parent::init();
     // We allow access to this controller regardless of live-status or ADMIN permission only
     // if on CLI or with the database not ready. The latter makes it less errorprone to do an
     // initial schema build without requiring a default-admin login.
     // Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
     $canAccess = Director::isDev() || !Security::database_is_ready() || Director::is_cli() && !SapphireTest::is_running_test() || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this, "This page is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
     }
 }
開發者ID:SustainableCoastlines,項目名稱:loveyourwater,代碼行數:12,代碼來源:DatabaseAdmin.php

示例11: init

 /**
  * standard Silverstripe method - required
  *
  */
 function init()
 {
     parent::init();
     // We allow access to this controller regardless of live-status or ADMIN permission only
     // or if on CLI.
     // Access to this controller is always allowed in "dev-mode", or if the user is ADMIN.
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     $canAccess = Director::isDev() || Director::is_cli() && !$isRunningTests || Permission::check("ADMIN") || Permission::check(EcommerceConfig::get("EcommerceRole", "admin_group_code"));
     if (!$canAccess) {
         return Security::permissionFailure($this, "The e-commerce development control panel is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
     }
 }
開發者ID:nieku,項目名稱:silverstripe-ecommerce,代碼行數:16,代碼來源:EcommerceDatabaseAdmin.php

示例12: init

	function init() {
		parent::init();

		$isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test());
		$canAccess = (
			Director::isDev() 
			// We need to ensure that DevelopmentAdminTest can simulate permission failures when running
			// "dev/tasks" from CLI.
			|| (Director::is_cli() && !$isRunningTests)
			|| Permission::check("ADMIN")
		);
		if(!$canAccess) return Security::permissionFailure($this);
	}
開發者ID:redema,項目名稱:sapphire,代碼行數:13,代碼來源:TaskRunner.php

示例13: getBasicAuthMember

 /**
  * @return \Member
  */
 protected static function getBasicAuthMember()
 {
     $realm = \Config::inst()->get('HttpAuth', 'Realm');
     $permissionCode = \Config::inst()->get('HttpAuth', 'PermissionCode');
     $isRunningTests = class_exists('SapphireTest', false) && \SapphireTest::is_running_test();
     $tryUsingSessionLogin = $isRunningTests || \Config::inst()->get('HttpAuth', 'TryUsingSessionLogin');
     try {
         $member = \BasicAuth::requireLogin($realm, $permissionCode, $tryUsingSessionLogin);
         return $member;
     } catch (\Exception $ex) {
         return null;
     }
 }
開發者ID:notthatbad,項目名稱:silverstripe-rest-api,代碼行數:16,代碼來源:HttpAuth.php

示例14: get_extra_config

 /**
  * Use table information and locales to dynamically build required table fields
  * @see DataExtension::get_extra_config()
  * @inheritdoc
  */
 public static function get_extra_config($class, $extension, $args)
 {
     if (!self::is_translatable_installed()) {
         // remain silent during a test
         if (SapphireTest::is_running_test()) {
             return null;
         }
         // raise an error otherwise
         user_error('Translatable module is not installed but required.', E_USER_WARNING);
         return null;
     }
     if ($args) {
         self::$arguments[$class] = $args;
     }
     return array('db' => self::collectDBFields($class));
 }
開發者ID:bummzack,項目名稱:translatable-dataobject,代碼行數:21,代碼來源:TranslatableDataObject.php

示例15: init

 public function init()
 {
     parent::init();
     // We allow access to this controller regardless of live-status or ADMIN permission only
     // if on CLI or with the database not ready. The latter makes it less errorprone to do an
     // initial schema build without requiring a default-admin login.
     // Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     $canAccess = Director::isDev() || !Security::database_is_ready() || Director::is_cli() && !$isRunningTests || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this, "This page is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
     }
     //render the debug view
     $renderer = Object::create('DebugView');
     $renderer->writeHeader();
     $renderer->writeInfo(_t("Shop.DEVTOOLSTITLE", "Shop Development Tools"), Director::absoluteBaseURL());
 }
開發者ID:NobrainerWeb,項目名稱:silverstripe-shop,代碼行數:17,代碼來源:ShopDevelopmentAdmin.php


注:本文中的SapphireTest::is_running_test方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。