return static::getMimeTypeByExtension($file, $magicFile); } throw new InvalidConfigException('The fileinfo PHP extension is not installed.'); } $info = finfo_open(FILEINFO_MIME_TYPE, $magicFile); if ($info) { $result = finfo_file($info, $file); finfo_close($info); if ($result !== false) { return $result; } } return $checkExtension ? static::getMimeTypeByExtension($file, $magicFile) : null; }
{ // Because: https://bugs.php.net/bug.php?id=74980 if (PHP_VERSION_ID >= 70100 && strpos($message, 'Narrowing occurred during type inference. Please file a bug report') !== false) { return null; } return parent::handleError($code, $message, $file, $line); } /** * @inheritdoc */ public function getExceptionName($exception)
throw new InvalidConfigException('The fileinfo PHP extension is not installed.'); } $info = finfo_open(FILEINFO_MIME_TYPE, $magicFile); if ($info) { $result = finfo_file($info, $file); finfo_close($info); if ($result !== false) { return $result; } }
/** * @inheritdoc */ public static function getMimeType($file, $magicFile = null, $checkExtension = true) { $mimeType = parent::getMimeType($file, $magicFile, $checkExtension); // Be forgiving of SVG files, etc., that don't have an XML declaration if ($checkExtension && ($mimeType === null || !static::canTrustMimeType($mimeType))) { return static::getMimeTypeByExtension($file, $magicFile) ?? $mimeType; }
$this->isNew = false; $this->extension = $sourceModel->extension; $this->size = @filesize($sourceModel->getFilePath()); try { $this->mimeType = FileHelper::getMimeType($sourceModel->getFilePath()); } catch (InvalidConfigException $e) { // just ignore } $imageInfo = @getimagesize($sourceModel->getFilePath());
$transformedImages = []; foreach ($transforms as $transform) { if ($config->getSetting('noop', $transform)) { $msg = Craft::t('imager', 'Noop activated, returning “{path}”.', ['path' => $sourceModel->url]); Craft::info($msg, __METHOD__); $transformedImages[] = new NoopImageModel($sourceModel, $transform); } else { $transformedImages[] = $this->getTransformedImage($sourceModel, $transform); } } $taskCreated = false;
Craft::error('Invalid transformer "'.self::$transformConfig->transformer.'"', __METHOD__); throw new ImagerException('Invalid transformer "'.self::$transformConfig->transformer.'"'); } /** @var TransformerInterface $transformer */ $transformer = new self::$transformers[self::$transformConfig->transformer](); $transformedImages = $transformer->transform($image, $transforms); } catch (ImagerException $e) { if (self::$transformConfig->suppressExceptions) { return null; } throw $e;
* @return mixed * * @throws ImagerException */ public function transformImage($file, $transform, $transformDefaults = null, $configOverrides = null) { $image = Plugin::$plugin->imager->transformImage($file, $transform, $transformDefaults, $configOverrides); return $image; } /** * Takes an array of models that supports getUrl() and getWidth(), and returns a srcset
$env->getExtension(SandboxExtension::class)->checkMethodAllowed($object, $method, $lineno, $source); } // Some objects throw exceptions when they have __call, and the method we try // to call is not supported. If ignoreStrictCheck is true, we should return null. try { $ret = $object->$method(...$arguments); } catch (\BadMethodCallException $e) { if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) { return; } throw $e; }
// Add deprecated support for the old DateTime methods if ($object instanceof \DateTime && ($value = self::_dateTimeAttribute($object, $item, $type)) !== false) { return $value; } try { return \twig_get_attribute($env, $source, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); } catch (UnknownMethodException $e) { // Copy twig_get_attribute()'s BadMethodCallException handling if ($ignoreStrictCheck || !$env->isStrictVariables()) { return null; } throw new RuntimeError($e->getMessage(), -1, $source);
{# for the 38vw image #} {% if image|length %} {% set imageHeight = image.height %} {% set imageWidth = image.width %} {% set transformedImages = craft.imager.transformImage(image, [ { width: 183}, { width: 292}, { width: 389}, { width: 486}, { width: 684},
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
{%- include "_includes/transforms/block-slider-" ~ imageOrientation with {'class': 'slider__image'} -%} </div> </div> {% else %} <div class="slider__slide {{ imageOrientation }} {{ imageOrientation }}-{{ counter }}"> <div class="slider__image-holder"> {%- include "_includes/transforms/block-slider-" ~ imageOrientation ~ "-" ~ counter with {'class': 'slider__image'} -%} </div> </div> {% if counter == 5 %} {% set counter = 1 %} {% else %} {% set counter = counter + 1 %}
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
{% switch block.type %} {% case 'heroBlock' %} {% include '_includes/_hero' with {'loop': loop } %} {% case 'titleTextCtaBlock' %} {% include '_includes/_title-text-cta' %} {% case 'sliderBlock' %} {% include '_includes/_slider' %} {% case 'imageBlock' %} {% include '_includes/_image-block' %} {% case 'quote' %} {% include '_includes/_quote' %} {% case 'textBlock' %} {% include '_includes/_text-block' %}
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
<div id="page-container" class="page {% if craft.app.request.isAjax %} ajax-template{% endif %}" {% if craft.app.request.isAjax and entry is defined %}data-title="{{ entry.title }}" data-namespace="{{ entry.section.handle|kebab }}"{% endif %} data-show-footer="true" data-dark-header="true" > {% cache globally using key 'pageBuilder-' ~ entry.id ~ '-' ~ entry.dateUpdated|date('U') %} {% set pageBuilder = entry.pageBuilder.all() ?? null %} {% if pageBuilder %} {% include '_includes/_page-builder' %} {% endif %} {% endcache %} {% include '_includes/_footer' %} </div> {% endblock %}
if (null !== $template && !$template instanceof self) { throw new \LogicException('A block must be a method on a \Twig\Template instance.'); } if (null !== $template) { try { $template->$block($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($template->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
</ul> </div> </nav> </transition> <main id="page-wrapper"> {% block content %}{% endblock %} </main> {% set cookieComplienceText = cookies.cookieComplienceText ?? null %} {% if cookieComplienceText %} <cookie-bar-component inline-template
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
{% extends (craft.app.request.isAjax) ? '_layouts/ajax' : '_layouts/main' %} {% block content %} <div id="page-container" class="page {% if craft.app.request.isAjax %} ajax-template{% endif %}" {% if craft.app.request.isAjax and entry is defined %}data-title="{{ entry.title }}" data-namespace="{{ entry.section.handle|kebab }}"{% endif %} data-show-footer="true" data-dark-header="true" > {% cache globally using key 'pageBuilder-' ~ entry.id ~ '-' ~ entry.dateUpdated|date('U') %}
return ob_get_clean(); } protected function displayWithErrorHandling(array $context, array $blocks = []) { try { $this->doDisplay($context, $blocks); } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } // this is mostly useful for \Twig\Error\LoaderError exceptions
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
if ($this->env->isDebug()) { ob_start(); } else { ob_start(function () { return ''; }); } try { $this->display($context); } catch (\Throwable $e) { while (ob_get_level() > $level) { ob_end_clean(); } throw $e;
* @param array $context An array of parameters to pass to the template */ public function render(array $context = []): string { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code return $this->template->render($context, \func_get_args()[1] ?? []); } /** * Displays the template. * * @param array $context An array of parameters to pass to the template
* @throws LoaderError When the template cannot be found * @throws SyntaxError When an error occurred during compilation * @throws RuntimeError When an error occurred during rendering */ public function render($name, array $context = []) { return $this->load($name)->render($context); } /** * Displays a template. * * @param string|TemplateWrapper $name The template name
// Render and return $renderingTemplate = $this->_renderingTemplate; $this->_renderingTemplate = $template; try { $output = $this->getTwig()->render($template, $variables); } finally { $this->_renderingTemplate = $renderingTemplate; $this->setTemplateMode($oldTemplateMode); } $this->afterRenderTemplate($template, $variables, $templateMode, $output);
$isRenderingPageTemplate = $this->_isRenderingPageTemplate; $this->_isRenderingPageTemplate = true; try { $this->beginPage(); echo $this->renderTemplate($template, $variables); $this->endPage(); } finally { $this->_isRenderingPageTemplate = $isRenderingPageTemplate; $this->setTemplateMode($oldTemplateMode); $output = ob_get_clean(); }
} // Prevent a response formatter from overriding the content-type header $this->response->format = YiiResponse::FORMAT_RAW; // Render and return the template $this->response->data = $view->renderPageTemplate($template, $variables, $templateMode); $headers = $this->response->getHeaders(); if ($generalConfig->sendContentLengthHeader) { $headers->setDefault('content-length', strlen($this->response->data)); }
// Merge any additional route params $routeParams = Craft::$app->getUrlManager()->getRouteParams(); unset($routeParams['template'], $routeParams['template']); $variables = array_merge($variables, $routeParams); return $this->renderTemplate($template, $variables); } /** * Shows the 'offline' template. * * @return Response
$args = $this->controller->bindActionParams($this, $params); Yii::debug('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
* @param string $route * @param array $params * @return Response|null The result of the action, normalized into a Response object */ public function runAction($route, $params = []) { $result = parent::runAction($route, $params); if ($result !== null) { if ($result instanceof Response) { return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
if (($response = $this->_processActionRequest($request)) !== null) { return $response; } // If we're still here, finally let Yii do it's thing. try { return parent::handleRequest($request); } catch (\Throwable $e) { $this->_unregisterDebugModule(); throw $e; } }
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
define('CRAFT_STORAGE_PATH', getenv('STORAGE_PATH')); } // Load and run Craft define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production'); $app = require CRAFT_VENDOR_PATH . '/craftcms/cms/bootstrap/web.php'; $app->run();