Sends an asset file to the client

@param CakeResponse $response The response object to use.
@param string $assetFile Path to the asset file in the file system
@param string $ext The extension of the file to determine its mime type
@return void
434302
protected function _deliverAsset(CakeResponse $response, $assetFile, $ext) {
		ob_start();
		$compressionEnabled = Configure::read('Asset.compress') && $response->compress();
		if ($response->type($ext) == $ext) {
			$contentType = 'application/octet-stream';
			$agent = env('HTTP_USER_AGENT');
			if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
				$contentType = 'application/octetstream';
			}
			$response->type($contentType);
		}
		if (!$compressionEnabled) {
			$response->header('Content-Length', filesize($assetFile));
		}
		$response->cache(filemtime($assetFile));
		$response->send();
		ob_clean();
		if ($ext === 'css' || $ext === 'js') {
			include $assetFile;
		} else {
			readfile($assetFile);
		}

		if ($compressionEnabled) {
			ob_end_flush();
		}
	}
785981
public function publishAssets($path, $forceCopy = false)
    {
        if (!Yii::app()->hasComponent('assetManager')) {
            throw new CException('Failed to locate the asset manager component.');
        }
        /* @var CAssetManager $assetManager */
        $assetManager = Yii::app()->getComponent('assetManager');
        $assetsUrl = $assetManager->publish($path, false, -1, $forceCopy);
        return $this->_assetsUrl = $assetsUrl;
    }
71400
public function assets(Response $response, $asset)
    {
        $filesystem = new Filesystem(new Adapter(FS2ADMIN));
        $expires = 8640000;

        try {
            // generate cache data
            $timestamp_string = gmdate('D, d M Y H:i:s ', $filesystem->getTimestamp($asset)) . 'GMT';
            $etag = md5($filesystem->read($asset));
            $mime_type = $filesystem->getMimetype($asset);
            if (0 !== strpos($mime_type, 'image')) {
                $mime_type = 'text/css';
            }

            $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
            $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;

            if ((($if_none_match && $if_none_match == "\"{$etag}\"") || (!$if_none_match)) &&
                ($if_modified_since && $if_modified_since == $timestamp_string)
            ) {
                return $response->withStatus('304');

            } else {
                $response = $response
                    ->withHeader('Last-Modified', $timestamp_string)
                    ->withHeader('ETag', "\"{$etag}\"");
            }

            // send out content type, expire time and the file
            $response->getBody()->write($filesystem->read($asset));
            return $response
                ->withHeader('Expires', gmdate('D, d M Y H:i:s ', time() + $expires) . 'GMT')
                ->withHeader('Content-Type', $mime_type)
                ->withHeader('Pragma', 'cache')
                ->withHeader('Cache-Control', 'cache');

        } catch (FileNotFoundException $e) {
            throw $e;
        }
    }
1114434
public function markAssetAsIncluded($assetType, $assetHandle = false)
    {
        $list = AssetList::getInstance();
        if ($assetType && $assetHandle) {
            $asset = $list->getAsset($assetType, $assetHandle);
        } else {
            $assetGroup = $list->getAssetGroup($assetType);
        }

        if (isset($assetGroup)) {
            $this->providedAssetGroup->addGroup($assetGroup);
        } elseif (isset($asset)) {
            $ap = new AssetPointer($asset->getAssetType(), $asset->getAssetHandle());
            $this->providedAssetGroup->add($ap);
        } else {
            $ap = new AssetPointer($assetType, $assetHandle);
            $this->providedAssetGroupUnmatched[] = $ap;
        }
    }
1081428
private function send(Response $response, $type = self::MASTER_REQUEST)
    {
        if (null !== $this->application && null !== $this->application->getEventDispatcher()) {
            $event = new FilterResponseEvent($this, $this->getRequest(), $type, $response);
            $this->application->getEventDispatcher()->dispatch('frontcontroller.response', $event);
            $this->application->getEventDispatcher()->dispatch(KernelEvents::RESPONSE, $event);
        }

        $response->send();
        $this->response = $response;
        $this->application->stop();
    }
230636
public function addAsset($type, $assetName, $fileName, $dependencies = array())
    {
        if (!isset($this->assets[$type]) || !is_array($this->assets[$type])) {
            $this->assets[$type] = array();
        }
        
        $asset = new Asset(
            $type,
            $assetName,
            $this->buildSourceFilePath($fileName),
            $dependencies
        );
        
        $this->assets[$type][$assetName] = $asset;
        $this->saveAssets();
    }
949638
public function validateAssetsPath(ExtensionContract $extension) {
        $targetPath = $this->configRepository->getPublicPath() . '/packages/antares';

        if( ! File::isWritable($targetPath) ) {
            throw new ExtensionException('The package [' . $extension->getPackage()->getName() . '] cannot access to the public assets path in [' . $targetPath . '].');
        }
    }
932526
protected function serveAsset($assetName)
    {
        $assetPath = $this->getLocalAssetPath($assetName);

        // Rudimentary mime type detection
        $mime = 'application/octet-stream';
        $map = [
            'ico' => 'image/vnd.microsoft.icon',
            'png' => 'image/png',
            'css' => 'text/css',
        ];

        $ext = substr($assetName, strrpos($assetName, '.') + 1);
        if (isset($map[$ext])) {
            $mime = $map[$ext];
        }

        $this->server->httpResponse->setHeader('Content-Type', $mime);
        $this->server->httpResponse->setHeader('Content-Length', filesize($assetPath));
        $this->server->httpResponse->setHeader('Cache-Control', 'public, max-age=1209600');
        $this->server->httpResponse->setStatus(200);
        $this->server->httpResponse->setBody(fopen($assetPath, 'r'));
    }
391977
public function execute(Framework $framework, WebRequest $request, Response $response)
    {
        // Display the main css group
        $this->assetCacheManager->displayAssetType(AssetManager::CSS);
        
        // Display the main js group
        $this->assetCacheManager->displayAssetType(AssetManager::JS);
    }
269979
protected function publishAssets(Extension $extension)
    {
        if ($extension->hasAssets()) {
            $this->filesystem->copyDirectory(
                $extension->getPath().'/assets',
                $this->app->publicPath().'/assets/extensions/'.$extension->getId()
            );
        }
    }
984399
public function send(SendResponseEvent $event)
    {


        // Console //

        if ($this->response instanceof ConsoleResponse) {
            $templateContent = $this->getTemplateContent('console');
            // inject details
            $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
            $this->response->setContent($templateContent);
            $this->response->setErrorLevel(1);

            return $this->sendResponse($this->response);
        }


        // HTTP //

        $this->response->setStatusCode(500);

        $requestHeaders = $this->request->getHeaders();
        if ($requestHeaders->has('accept')) {

            $accept = $requestHeaders->get('Accept');
            $responseHeaders = $this->response->getHeaders();
            $responseHeaders->clearHeaders();

            if ($accept->match('text/html') !== false) { // html

                // get template content
                $templateContent = $this->getTemplateContent($event->getParam('type'));
                // inject details
                $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
                $contentType = 'text/html; charset=utf-8';
                $responseHeaders->addHeaderLine('content-type', $contentType);
                $this->response->setContent($templateContent);

            } else if ($accept->match('application/json') !== false
                || $accept->match('application/hal+json') !== false) { // json

                // return api problem structured json
                $contentType = 'application/problem+json; charset=utf-8';
                $responseHeaders->addHeaderLine('content-type', $contentType);
                // get template
                $templateContent = $this->getTemplateContent('json');
                // inject details
                $templateContent = $this->injectTemplateContent($templateContent, $event->getParams());
                $this->response->setContent($templateContent);

            }
        }

        $this->sendResponse($this->response);

    }
878116
public function handleFile(string $fileName): void
	{
		$file = $this->getFileInfo($fileName);
		if (strpos($file->type, 'image') !== false) {
			$response = new FileResponse($this->getFullPath($file->name), $file->name, $file->type, false);
			$this->presenter->sendResponse($response);
		} else {
			exit;
		}
	}
771730
function (request, response) {
      var locale = request.params.locale;
      var sendFile = response.sendFile || response.sendfile;
      sendFile.apply(response, [path.join(configuration.directory, locale + configuration.extension)]);
    }
1259894
function forEachAsset(assets, callback, finishedCallback) {
	async.forEachSeries(Object.keys(assets), function(extensionName, nextGroup) {
		var extensionAssets = assets[extensionName];
		async.forEachSeries(Object.keys(extensionAssets), function(groupName, nextAssetType) {
			var group = extensionAssets[groupName];
			async.forEachSeries(group, function(asset, nextAsset) {
				callback({
					extensionAssets : extensionAssets,
					extensionName : extensionName,
					group : group,
					groupName : groupName,
					asset : asset
				}, nextAsset);
			}, function(err) { nextAssetType(err); });
		}, function(err) { nextGroup(err); });
	}, function(err) { finishedCallback(err); });
}
820299
public function actionCanEdit(): Response
    {
        $this->requireAcceptsJson();
        $this->requirePostRequest();

        $assetId = Craft::$app->getRequest()->getRequiredBodyParam('assetId');
        $asset = Asset::find()->id($assetId)->one();

        if (!$asset) {
            return $this->asJson([
                'success' => false
            ]);
        }

        /** @var Volume $volume */
        $volume = $asset->getVolume();
        $user = Craft::$app->getUser()->getIdentity();

        return $this->asJson([
            'success' => (
                $user->can('saveAssetInVolume:' . $volume->uid) &&
                $user->can('deleteFilesAndFoldersInVolume:' . $volume->uid)
            ),
        ]);
    }
1039797
private function mextend($dir, $ext)
	{
		$this->__cached = preg_replace_callback($this->usingDirective('extends\((.*?)\)'), function($match)  use ($dir, $ext) {
			$view = str_replace("'", "", $match[1]);
			$view = str_replace('"', '', $view);

			$path = $dir . $this->DS .$view . $ext;
			$view = $view;

			if (file_exists($path)) {
				return '<!--%' .base64_encode($view). '%-->' . PHP_EOL . file_get_contents($path);
			}
			else {
				$this->exception('"' . $path . '" does not exist.');
			}
		}, $this->__cached);

		$this->mcustom($this->__directives);
	}
33584
public function send()
    {
        deprecationWarning('Response::send() will be removed in 4.0.0');

        if ($this->hasHeader('Location') && $this->_status === 200) {
            $this->statusCode(302);
        }

        $this->_setContent();
        $this->sendHeaders();

        if ($this->_file) {
            $this->_sendFile($this->_file, $this->_fileRange);
            $this->_file = null;
            $this->_fileRange = [];
        } else {
            $this->_sendContent($this->body());
        }

        if (function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        }
    }