本文整理汇总了PHP中Craft::app方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::app方法的具体用法?PHP Craft::app怎么用?PHP Craft::app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::app方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getService
/**
* @return SproutEmail_DefaultMailerService
*/
public function getService()
{
if (is_null($this->service)) {
$this->service = Craft::app()->getComponent('sproutEmail_defaultMailer');
}
return $this->service;
}
示例2: init
public function init()
{
parent::init();
$this->mailers = Craft::app()->getComponent('sproutEmail_mailer');
$this->entries = Craft::app()->getComponent('sproutEmail_entries');
$this->campaigns = Craft::app()->getComponent('sproutEmail_campaigns');
$this->notifications = Craft::app()->getComponent('sproutEmail_notifications');
}
示例3: init
public function init()
{
parent::init();
$this->link = Craft::app()->getComponent('sproutFields_linkField');
$this->email = Craft::app()->getComponent('sproutFields_emailField');
$this->emailSelect = Craft::app()->getComponent('sproutFields_emailSelectField');
$this->phone = Craft::app()->getComponent('sproutFields_phoneField');
}
示例4: init
public function init()
{
parent::init();
$this->entries = Craft::app()->getComponent('sproutForms_entries');
$this->fields = Craft::app()->getComponent('sproutForms_fields');
$this->forms = Craft::app()->getComponent('sproutForms_forms');
$this->groups = Craft::app()->getComponent('sproutForms_groups');
$this->settings = Craft::app()->getComponent('sproutForms_settings');
}
示例5: init
public function init()
{
parent::init();
$this->meta = Craft::app()->getComponent('sproutSeo_meta');
$this->defaults = Craft::app()->getComponent('sproutSeo_metaDefaults');
$this->overrides = Craft::app()->getComponent('sproutSeo_metaOverrides');
$this->sitemap = Craft::app()->getComponent('sproutSeo_sitemap');
$this->settings = Craft::app()->getComponent('sproutSeo_settings');
$this->redirects = Craft::app()->getComponent('sproutSeo_redirects');
}
示例6: patrol
/**
* Returns an instance of the Patrol service and enables proper hinting and service layer encapsulation
*
* @return PatrolService
*/
function patrol()
{
return Craft::app()->getComponent('patrol');
}
示例7: doxter
/**
* Enables us to have a single point of access to our service layer and proper hinting
*
* @return DoxterService
*/
function doxter()
{
return Craft::app()->getComponent('doxter');
}
示例8: craft
/**
* Returns the current craft() instance. This is a wrapper function for the Craft::app() instance.
*
* @return WebApp|ConsoleApp
*/
function craft()
{
return Craft::app();
}
示例9: sendFile
/**
* Sends a file to the user.
*
* We’re overriding this from {@link \CHttpRequest::sendFile()} so we can have more control over the headers.
*
* @param string $path The path to the file on the server.
* @param string $content The contents of the file.
* @param array|null $options An array of optional options. Possible keys include 'forceDownload', 'mimeType',
* and 'cache'.
* @param bool|null $terminate Whether the request should be terminated after the file has been sent.
* Defaults to `true`.
*
* @throws HttpException
* @return null
*/
public function sendFile($path, $content, $options = array(), $terminate = true)
{
$fileName = IOHelper::getFileName($path, true);
// Clear the output buffer to prevent corrupt downloads. Need to check the OB status first, or else some PHP
// versions will throw an E_NOTICE since we have a custom error handler
// (http://pear.php.net/bugs/bug.php?id=9670)
if (ob_get_length() !== false) {
// If zlib.output_compression is enabled, then ob_clean() will corrupt the results of output buffering.
// ob_end_clean is what we want.
ob_end_clean();
}
// Default to disposition to 'download'
$forceDownload = !isset($options['forceDownload']) || $options['forceDownload'];
if ($forceDownload) {
HeaderHelper::setDownload($fileName);
}
if (empty($options['mimeType'])) {
if (($options['mimeType'] = \CFileHelper::getMimeTypeByExtension($fileName)) === null) {
$options['mimeType'] = 'text/plain';
}
}
HeaderHelper::setHeader(array('Content-Type' => $options['mimeType'] . '; charset=utf-8'));
$fileSize = mb_strlen($content, '8bit');
$contentStart = 0;
$contentEnd = $fileSize - 1;
$httpVersion = $this->getHttpVersion();
if (isset($_SERVER['HTTP_RANGE'])) {
HeaderHelper::setHeader(array('Accept-Ranges' => 'bytes'));
// Client sent us a multibyte range, can not hold this one for now
if (mb_strpos($_SERVER['HTTP_RANGE'], ',') !== false) {
HeaderHelper::setHeader(array('Content-Range' => 'bytes ' . $contentStart - $contentEnd / $fileSize));
throw new HttpException(416, 'Requested Range Not Satisfiable');
}
$range = str_replace('bytes=', '', $_SERVER['HTTP_RANGE']);
// range requests starts from "-", so it means that data must be dumped the end point.
if ($range[0] === '-') {
$contentStart = $fileSize - mb_substr($range, 1);
} else {
$range = explode('-', $range);
$contentStart = $range[0];
// check if the last-byte-pos presents in header
if (isset($range[1]) && is_numeric($range[1])) {
$contentEnd = $range[1];
}
}
// Check the range and make sure it's treated according to the specs.
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
// End bytes can not be larger than $end.
$contentEnd = $contentEnd > $fileSize ? $fileSize - 1 : $contentEnd;
// Validate the requested range and return an error if it's not correct.
$wrongContentStart = $contentStart > $contentEnd || $contentStart > $fileSize - 1 || $contentStart < 0;
if ($wrongContentStart) {
HeaderHelper::setHeader(array('Content-Range' => 'bytes ' . $contentStart - $contentEnd / $fileSize));
throw new HttpException(416, 'Requested Range Not Satisfiable');
}
HeaderHelper::setHeader("HTTP/{$httpVersion} 206 Partial Content");
HeaderHelper::setHeader(array('Content-Range' => 'bytes ' . $contentStart - $contentEnd / $fileSize));
} else {
HeaderHelper::setHeader("HTTP/{$httpVersion} 200 OK");
}
// Calculate new content length
$length = $contentEnd - $contentStart + 1;
if (!empty($options['cache'])) {
$cacheTime = 31536000;
// 1 year
HeaderHelper::setHeader(array('Expires' => gmdate('D, d M Y H:i:s', time() + $cacheTime) . ' GMT'));
HeaderHelper::setHeader(array('Pragma' => 'cache'));
HeaderHelper::setHeader(array('Cache-Control' => 'max-age=' . $cacheTime));
$modifiedTime = IOHelper::getLastTimeModified($path);
HeaderHelper::setHeader(array('Last-Modified' => gmdate("D, d M Y H:i:s", $modifiedTime->getTimestamp()) . ' GMT'));
} else {
if (!$forceDownload) {
HeaderHelper::setNoCache();
} else {
// Fixes a bug in IE 6, 7 and 8 when trying to force download a file over SSL:
// https://stackoverflow.com/questions/1218925/php-script-to-download-file-not-working-in-ie
HeaderHelper::setHeader(array('Pragma' => '', 'Cache-Control' => ''));
}
}
if ($options['mimeType'] == 'application/x-javascript' || $options['mimeType'] == 'text/css') {
HeaderHelper::setHeader(array('Vary' => 'Accept-Encoding'));
}
if (!ob_get_length()) {
HeaderHelper::setLength($length);
}
//.........这里部分代码省略.........
示例10: sproutEmailDefaultMailer
/**
* @return SproutEmail_DefaultMailerService
*/
function sproutEmailDefaultMailer()
{
return Craft::app()->getComponent('sproutEmail_defaultMailer');
}
示例11: sproutForms
/**
* @return SproutFormsService
*/
function sproutForms()
{
return Craft::app()->getComponent('sproutForms');
}
示例12: sproutSeo
/**
* @return SproutSeoService
*/
function sproutSeo()
{
return Craft::app()->getComponent('sproutSeo');
}
示例13: sendFile
/**
* Sends a file to the user.
*
* We're overriding this from \CHttpRequest so we can have more control over the headers.
*
* @param string $path
* @param string $content
* @param array|null $options
* @param bool|null $terminate
*/
public function sendFile($path, $content, $options = array(), $terminate = true)
{
$fileName = IOHelper::getFileName($path, true);
// Clear the output buffer to prevent corrupt downloads.
// Need to check the OB status first, or else some PHP versions will throw an E_NOTICE since we have a custom error handler
// (http://pear.php.net/bugs/bug.php?id=9670)
if (ob_get_length() !== false) {
ob_clean();
}
// Default to disposition to 'download'
if (!isset($options['forceDownload']) || $options['forceDownload']) {
header('Content-Disposition: attachment; filename="' . $fileName . '"');
}
if (empty($options['mimeType'])) {
if (($options['mimeType'] = \CFileHelper::getMimeTypeByExtension($fileName)) === null) {
$options['mimeType'] = 'text/plain';
}
}
header('Content-type: ' . $options['mimeType']);
if (!empty($options['cache'])) {
$cacheTime = 31536000;
// 1 year
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $cacheTime) . ' GMT');
header('Pragma: cache');
header('Cache-Control: max-age=' . $cacheTime);
$modifiedTime = IOHelper::getLastTimeModified($path);
header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $modifiedTime->getTimestamp()) . ' GMT');
} else {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
}
if (!ob_get_length()) {
header('Content-Length: ' . (function_exists('mb_strlen') ? mb_strlen($content, '8bit') : strlen($content)));
}
if ($options['mimeType'] == 'application/x-javascript' || $options['mimeType'] == 'text/css') {
header('Vary: Accept-Encoding');
}
if ($terminate) {
// clean up the application first because the file downloading could take long time
// which may cause timeout of some resources (such as DB connection)
ob_start();
Craft::app()->end(0, false);
ob_end_clean();
echo $content;
exit(0);
} else {
echo $content;
}
}