Forces image caching and returns path to cached image.

@param string $basePath
@param string $path
@param string $filter

@return string|null
965130
public function cacheImage($basePath, $path, $filter)
    {
        $path = '/'.ltrim($path, '/');

        //TODO: find out why I need double urldecode to get a valid path
        $browserPath = urldecode(urldecode($this->cachePathResolver->getBrowserPath($path, $filter)));

        if (!empty($basePath) && 0 === strpos($browserPath, $basePath)) {
             $browserPath = substr($browserPath, strlen($basePath));
        }

         // if cache path cannot be determined, return 404
        if (null === $browserPath) {
            return null;
        }

        $realPath = $this->webRoot.$browserPath;
        
        $sourcePathRoot = $this->filterManager->getOption($filter, "source_root", $this->sourceRoot);
        $sourcePath = $sourcePathRoot.$path;

        // if the file has already been cached, just return path
        if (is_file($realPath)) {
            return $realPath;
        }

        if (!is_file($sourcePath)) {
            return null;
        }

        $dir = pathinfo($realPath, PATHINFO_DIRNAME);

        if (!is_dir($dir)) {
            try {
                if (false === $this->filesystem->mkdir($dir)) {
                    throw new \RuntimeException(sprintf(
                        'Could not create directory %s', $dir
                    ));
                }
            } catch (\Exception $e) {
                if (!is_dir($dir)) {
                    throw $e;
                }
            }
        }

        // TODO: get rid of hard-coded quality and format
        $this->filterManager->getFilter($filter)
            ->apply($this->imagine->open($sourcePath))
            ->save($realPath, array(
                'quality' => $this->filterManager->getOption($filter, "quality", 100),
                'format'  => $this->filterManager->getOption($filter, "format", null)
            ))
        ;
        
        try {
            if (!chmod($realPath, $this->permissions))
            {
                throw new \RuntimeException(sprintf(
                    'Could not set permissions %s on image saved in %s', $this->permissions, $realPath
                ));
            }
            
        } catch (Exception $e) {
            throw $e;
        }
        
        return $realPath;
    }
1158404
public function getUrlOfFilteredImageWithRuntimeFilters($path, $filter, array $runtimeFilters = [], $resolver = null)
    {
        $runtimePath = $this->cacheManager->getRuntimePath($path, $runtimeFilters);
        if ($this->cacheManager->isStored($runtimePath, $filter, $resolver)) {
            return $this->cacheManager->resolve($runtimePath, $filter, $resolver);
        }

        $filteredBinary = $this->createFilteredBinary(
            $path,
            $filter,
            $runtimeFilters
        );

        $this->cacheManager->store(
            $filteredBinary,
            $runtimePath,
            $filter,
            $resolver
        );

        return $this->cacheManager->resolve($runtimePath, $filter, $resolver);
    }
974464
public function withBasePath($basePath)
    {
        if (!is_string($basePath)) {
            throw new InvalidArgumentException('Uri path must be a string');
        }
        if (!empty($basePath)) {
            $basePath = '/' . trim($basePath, '/');
        }
        $clone = clone $this;

        if ($basePath !== '/') {
            $clone->basePath = Validator::checkPath($basePath);
        }

        return $clone;
    }
1352344
public function getMinifyUrl($paths, $basePath = null)
    {
        return $this->container->get('rednose_combo_handler.templating.helper.minify')->getUrl($paths, $basePath);
    }
1210099
public function load($basePath)
    {
        $this->basePath = $basePath;
        $this->renderer = new Renderer($this->getViewsPath());

        return
            $this
                ->loadCustomTables()
                ->loadPostTypes()
                ->loadFieldGroups()
                ->loadAcfJson()
                ->loadActions()
                ->loadShortCodes()
                ->loadOptionScreens()
                ->loadCliCommands();
    }
851363
private function addBaseurl2AnchorUrls(&$filtered, $baseurl)
    {
        $textf   = $this->di->get("textfilter");
        $url     = $this->di->get("url");
        $request = $this->di->get("request");
        $part = $request->getRoute();

        // Use callback to url->create() instead of string concat
        $callback = function ($route) use ($url, $baseurl, $part) {
            if (!empty($route) && $route[0] == "!") {
                return $url->asset(substr($route, 1), $baseurl);
            }

            if (isset($route[0])
                && isset($route[1])
                && $route[0] === "."
                && $route[1] === "/"
            ) {
                return $url->create(
                    substr($route, 2),
                    $baseurl . $part
                );
            }

            return $url->create($route, $baseurl);
        };

        $filtered->text =
            $textf->addBaseurlToRelativeLinks($filtered->text, $baseurl, $callback);
    }
828141
public static function apply($context, $method, $filter)
    {
        static::$_cachedFilters = [];

        if (is_object($context)) {
            $instance = $context;
            $class = get_class($context);
        } else {
            $class = $context;
            $instance = null;
        }

        $filter = $filter->bindTo($instance, $class);

        $ref = static::_ref($context, $method);
        if (!isset(static::$_filters[$ref])) {
            static::$_filters[$ref] = [$filter];
        } else {
            array_unshift(static::$_filters[$ref], $filter);
        }
        return $ref . '|' . (count(static::$_filters[$ref]) - 1);
    }
93220
public function applyFilter($path, $filter, $absolute = false)
    {
        return $this->cachePathResolver->getBrowserPath($path, $filter, $absolute);
    }
628111
public function compile($lessFile, $basePath = null)
    {
        try {
            $basePath = $this->_prepareBasepath($basePath, dirname($lessFile));

            $cache = new Cache($this->_options);
            $cache->setFile($lessFile, $basePath);

            $isExpired = $cache->isExpired();
            $isForce   = $this->_options->get('force', false, 'bool');

            if ($isForce || $cache->isExpired()) {
                $result = $this->_driver->compile($lessFile, $basePath);
                $cache->save($result);
            }

            $isExpired = ($isForce) ? true : $isExpired;
            $return = [FS::clean($cache->getFile(), '/'), $isExpired];

        } catch (\Exception $e) {
            $message = 'Less error: ' . $e->getMessage();
            throw new Exception($message);
        }

        return $return;
    }
119654
private function removeBasePath(string $path)
    {
        if (\strpos($path, $this->basePath) === 0) {
            $path = \substr($path, \strlen($this->basePath)) ?: '';
        }

        if ($path !== '' && $path[0] !== '/') {
            return '/' . $path;
        }

        return $path;
    }
1165778
public function getBaseUrl($path)
    {
        if (1 === \count($this->baseUrls)) {
            return $this->baseUrls[0];
        }

        return $this->baseUrls[$this->chooseBaseUrl($path)];
    }
216090
public function base_path($path = null)
    {
        return empty($path) ? $this->path : $this->path . $path;
    }
1106914
public function getStorageBaseDirectory($basePath = null)
    {
        // Get base storage path configuration
        $storage = $this->get('storage');

        // Check if storage is relative to the application path or not
        $relative = $storage['path_is_relative'] ?: true;

        return ($relative ? $basePath . DIRECTORY_SEPARATOR : '') . $storage['base_dir'];
    }
134220
public function basePath($basePath = null)
    {
        if (!func_num_args()) {
            return $this->_basePath;
        }
        $this->_basePathTmp = $basePath;
        if ($this->_ignorePath) {
            $basePath = preg_replace($this->_ignorePath, '', $basePath);
        }
        $this->_basePath = $basePath && $basePath !== '/' ? '/' . trim($basePath, '/') : '';
        return $this;
    }
912756
private function createFilteredBinary($path, $filter, array $runtimeFilters = [])
    {
        $binary = $this->dataManager->find($filter, $path);

        try {
            return $this->filterManager->applyFilter($binary, $filter, [
                'filters' => $runtimeFilters,
            ]);
        } catch (NonExistingFilterException $e) {
            $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $path, $e->getMessage());

            $this->logger->debug($message);

            throw $e;
        }
    }
243953
public function getViewsPath($basePath = null)
    {
        $views = $this->get('views');
        if (empty($views)) {
            // Fallback to default
            return $basePath . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'views';
        }

        return $basePath . DIRECTORY_SEPARATOR . $views['base_dir'];
    }
925757
public function getImageUrl(Media $media, $basepath)
    {
        if ($media->getUrl() === parse_url($media->getUrl(), PHP_URL_PATH)) {
            return $basepath . $media->getUrl();
        }

        return $media->getUrl();
    }