Timber\ImageHelper::_operate PHP Метод

_operate() приватный статический Метод

Main method that applies operation to src image: 1. break down supplied URL into components 2. use components to determine result file and URL 3. check if a result file already exists 4. otherwise, delegate to supplied TimberImageOperation
private static _operate ( string $src, object $op, boolean $force = false ) : string
$src string an URL (absolute or relative) to an image
$op object object of class TimberImageOperation
$force boolean if true, remove any already existing result file and forces file generation
Результат string URL to the new image - or the source one if error
    private static function _operate($src, $op, $force = false)
    {
        if (empty($src)) {
            return '';
        }
        $external = false;
        // if external image, load it first
        if (URLHelper::is_external_content($src)) {
            $src = self::sideload_image($src);
            $external = true;
        }
        // break down URL into components
        $au = self::analyze_url($src);
        // build URL and filenames
        $new_url = self::_get_file_url($au['base'], $au['subdir'], $op->filename($au['filename'], $au['extension']), $au['absolute']);
        $destination_path = self::_get_file_path($au['base'], $au['subdir'], $op->filename($au['filename'], $au['extension']));
        $source_path = self::_get_file_path($au['base'], $au['subdir'], $au['basename']);
        $new_url = apply_filters('timber/image/new_url', $new_url);
        $destination_path = apply_filters('timber/image/new_path', $destination_path);
        // if already exists...
        if (file_exists($destination_path)) {
            if ($force || filemtime($source_path) > filemtime($destination_path)) {
                // Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
                unlink($destination_path);
            } else {
                // return existing file (caching)
                return $new_url;
            }
        }
        // otherwise generate result file
        if ($op->run($source_path, $destination_path)) {
            if (get_class($op) === 'Timber\\Image\\Operation\\Resize' && $external) {
                $new_url = strtolower($new_url);
            }
            return $new_url;
        } else {
            // in case of error, we return source file itself
            return $src;
        }
    }