@param $source

@return array
@throws ImagerException
766773
protected function getSourceImageDimensions($source): array
    {
        if ($source instanceof Asset) {
            return [$source->getWidth(), $source->getHeight()];
        }

        if ($this->profileConfig !== null && $this->profileConfig->getExternalImageDimensions) {
            $sourceModel = new LocalSourceImageModel($source);
            $sourceModel->getLocalCopy();

            $sourceImageInfo = @getimagesize($sourceModel->getFilePath());

            return [$sourceImageInfo[0], $sourceImageInfo[1]];
        }

        return [0, 0];
    }
6245
public function relGlob($source)
    {
        $list = (array)$this->glob($source);
        foreach ($list as $key => $item) {
            $list[$key] = FS::getRelative($item, $this->root, '/');
        }

        return $list;
    }
1148561
protected function getListMap($source)
    {
        // Extract Map from ID / Text Fields:
        
        if ($source instanceof SS_List) {
            $source = $source->map($this->getIDField(), $this->getTextField());
        }
        
        // Convert Map to Array:
        
        if ($source instanceof Map) {
            $source = $source->toArray();
        }
        
        // Determine Invalid Types:
        
        if (!is_array($source) && !($source instanceof ArrayAccess)) {
            user_error('$source passed in as invalid type', E_USER_ERROR);
        }
        
        // Answer Data Source:
        
        return $source;
    }
736742
protected function getSourceAttributes()
    {
        $info = getimagesize($this->source);

        list($width, $height) = $info;

        return [
            'width'    => $width,
            'height'   => $height,
            'ratio'    => $this->ratio($width, $height),
            'size'     => filesize($this->source),
            'type'     => $info['mime']
        ];
    }
1216053
public function match($source)
    {
        return $this->_enabled && $this->_matcher !== null ? $this->_matcher->match($source, $this->factory) : [];
    }
48373
public static function objectToArray($source): array
    {
        $result = [];

        if (is_array($source)) {
            return $source;
        }

        if (!is_object($source)) {
            return $result;
        }

        $json = json_encode($source);
        if ($json === false) {
            return $result;
        }

        $array = json_decode($json, true);
        if ($array === null) {
            return $result;
        }
        $result = $array;

        return $result;
    }
4026
private function getTransformedImage($sourceModel, $transform)
    {
        /** @var ConfigModel $settings */
        $config = ImagerService::getConfig();

        if ($config->getSetting('noop', $transform)) {
            // todo : just return source image unmodified
        }

        if ($this->imagineInstance === null) {
            $msg = Craft::t('imager', 'Imagine instance was not created for driver “{driver}”.', ['driver' => ImagerService::$imageDriver]);
            Craft::error($msg, __METHOD__);
            throw new ImagerException($msg);
        }

        // Create target model
        $targetModel = new LocalTargetImageModel($sourceModel, $transform);

        // Set save options
        $saveOptions = $this->getSaveOptions($targetModel->extension, $transform);

        // Do transform if transform doesn't exist, cache is disabled, or cache expired
        if (!$config->getSetting('cacheEnabled', $transform) ||
            !file_exists($targetModel->getFilePath()) ||
            (($config->getSetting('cacheDuration', $transform) !== false) && (FileHelper::lastModifiedTime($targetModel->getFilePath()) + $config->getSetting('cacheDuration', $transform) < time()))
        ) {
            // Make sure that we have a local copy.
            $sourceModel->getLocalCopy();

            // Check all the things that could go wrong(tm)
            if (!realpath($sourceModel->path)) {
                $msg = Craft::t('imager', 'Source folder “{sourcePath}” does not exist', ['sourcePath' => $sourceModel->path]);
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }

            if (!realpath($targetModel->path)) {
                try {
                    FileHelper::createDirectory($targetModel->path);
                } catch (Exception $e) {
                    // ignore for now, trying to create
                }

                if (!realpath($targetModel->path)) {
                    $msg = Craft::t('imager', 'Target folder “{targetPath}” does not exist and could not be created', ['targetPath' => $targetModel->path]);
                    Craft::error($msg, __METHOD__);
                    throw new ImagerException($msg);
                }

                $targetModel->path = realpath($targetModel->path);
            }

            try {
                $targetPathIsWriteable = FileHelper::isWritable($targetModel->path);
            } catch (ErrorException $e) {
                $targetPathIsWriteable = false;
            }

            if ($targetModel->path && !$targetPathIsWriteable) {
                $msg = Craft::t('imager', 'Target folder “{targetPath}” is not writeable', ['targetPath' => $targetModel->path]);
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }

            if (!file_exists($sourceModel->getFilePath())) {
                $msg = Craft::t('imager', 'Requested image “{fileName}” does not exist in path “{sourcePath}”', ['fileName' => $sourceModel->filename, 'sourcePath' => $sourceModel->path]);
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }

            if (!Craft::$app->images->checkMemoryForImage($sourceModel->getFilePath())) {
                $msg = Craft::t('imager', 'Not enough memory available to perform this image operation.');
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }

            // Create the imageInstance. only once if reuse is enabled, or always
            if ($this->imageInstance === null || !$config->getSetting('instanceReuseEnabled', $transform)) {
                $this->imageInstance = $this->imagineInstance->open($sourceModel->getFilePath());
            }

            $animated = false;

            // Check if this is an animated gif and we're using Imagick
            if ($sourceModel->extension === 'gif' && ImagerService::$imageDriver !== 'gd' && $this->imageInstance->layers()) {
                $animated = true;
            }

            // Run tranforms, either on each layer of an animated gif, or on the whole image.
            if ($animated) {
                if ($this->imageInstance->layers()) {
                    $this->imageInstance->layers()->coalesce();
                }

                // We need to create a new image instance with the target size, or letterboxing will be wrong.
                $originalSize = $this->imageInstance->getSize();
                $resizeSize = ImagerHelpers::getResizeSize($originalSize, $transform, $config->getSetting('allowUpscale', $transform));
                $layers = $this->imageInstance->layers() ?? [];
                $gif = $this->imagineInstance->create($resizeSize);

                if ($gif->layers()) {
                    $gif->layers()->remove(0);
                }

                list($startFrame, $endFrame, $interval) = $this->getFramesVars($layers, $transform);

                for ($i = $startFrame; $i <= $endFrame; $i += $interval) {
                    if (isset($layers[$i])) {
                        $layer = $layers[$i];
                        $this->transformLayer($layer, $transform, $sourceModel->extension);
                        $gif->layers()->add($layer);
                    }
                }

                $this->imageInstance = $gif;
            } else {
                $this->transformLayer($this->imageInstance, $transform, $sourceModel->extension);
            }

            // If Image Driver is imagick and removeMetadata is true, remove meta data
            if (ImagerService::$imageDriver === 'imagick' && $config->getSetting('removeMetadata', $transform)) {
                $this->imageInstance->strip();
            }

            // Convert the image to RGB before converting to webp/saving
            if ($config->getSetting('convertToRGB', $transform)) {
                $this->imageInstance->usePalette(new RGB());
            }

            // Save the transform
            if ($targetModel->extension === 'webp') {
                if (ImagerService::hasSupportForWebP()) {
                    $this->saveAsWebp($this->imageInstance, $targetModel->getFilePath(), $sourceModel->extension, $saveOptions);
                } else {
                    $msg = Craft::t('imager', 'This version of {imageDriver} does not support the webp format. You should use “craft.imager.serverSupportsWebp” in your templates to test for it.', ['imageDriver' => ImagerService::$imageDriver === 'gd' ? 'GD' : 'Imagick']);
                    Craft::error($msg, __METHOD__);
                    throw new ImagerException($msg);
                }
            } else {
                $this->imageInstance->save($targetModel->getFilePath(), $saveOptions);
            }

            $targetModel->isNew = true;
        }

        // create CraftTransformedImageModel for transformed image
        $imageModel = new CraftTransformedImageModel($targetModel, $sourceModel, $transform);

        return $imageModel;
    }
344033
public final static function decode(string $source): array {
		if (is_null($source = json_decode($source, true)) && json_last_error() !== JSON_ERROR_NONE){
			throw new \Exception('Invalid json format!');
		}

		return $source;
	}
786270
private function getDeletedFields(Source $source)
    {
        $fields = array();
        $fields += array(
            'undelete' => array(
                'type' => 'button',
                'value' => $this->t('undelete'),
                'ajax' => array(
                    'service' => 'entry_deletestatus_set',
                    'parent_type' => $this->source->getType(),
                    'parent_source' => $this->source->getId(),
                    'type' => $source->getType(),
                    'source' => $source->getId(),
                    'value' => API::Entry_Delete,
                ),
            ),
            'send' => array(
                'type' => 'button',
                'value' => $this->t('send_again'),
                'ajax' => array(
                    'service' => 'invoice_add',
                    'parent_type' => $this->source->getType(),
                    'parent_source' => $this->source->getId(),
                    'type' => $source->getType(),
                    'source' => $source->getId(),
                    'value' => 1,
                ),
            ),
        );
        return $fields;
    }
615914
public function retrieve(Model $model, $source)
    {
        return [
            'from' => parent::retrieve($model, $this->getAttributeFrom()),
            'to'   => parent::retrieve($model, $this->getAttributeTo()),
        ];
    }
266695
protected function getListMap($source)
    {
        // Extract source as an array
        if ($source instanceof SS_List) {
            $source = $source->map();
        }
        if ($source instanceof Map) {
            $source = $source->toArray();
        }
        if (!is_array($source) && !($source instanceof ArrayAccess)) {
            user_error('$source passed in as invalid type', E_USER_ERROR);
        }

        return $source;
    }
13961
protected function getSourceAsArray($source)
    {
        if (!is_array($source) && !($source instanceof ArrayAccess)) {
            user_error('$source passed in as invalid type', E_USER_ERROR);
        }
        
        if ($source instanceof SS_List || $source instanceof Map) {
            $source = $source->toArray();
        }
        
        return $source;
    }
595946
public function getImages()
    {
        $result = [];
        if ($this->getImage()) {
            $result[] = $this->getImage();
        }

        if (null == $this->getDOMDocument()) {
            return $result;
        }

        foreach ($this->getDOMDocument()->getElementsByTagName('img') as $img) {
            if ($src = $img->getAttribute('src')) {
                $result[] = $src;
            }
        }

        if ($this->configuration->getFixRelativeURLs()) {
            foreach ($result as &$imgSrc) {
                $imgSrc = $this->toAbsoluteURI($imgSrc);
            }
        }

        $result = array_unique(array_filter($result));

        return $result;
    }
1156788
public static function getBlueprints($source)
    {
        $blueprint_file = $source . 'blueprints.yaml';
        if (!file_exists($blueprint_file)) {
            return false;
        }

        $file = YamlFile::instance($blueprint_file);
        $blueprint = (array)$file->content();
        $file->free();

        return $blueprint;
    }
241355
private function getConceptFields(Source $source)
    {
        $fields = array();
        $fields += array(
            'send' => array(
                'type' => 'button',
                'value' => $this->t('send_again'),
                'ajax' => array(
                    'service' => 'invoice_add',
                    'parent_type' => $this->source->getType(),
                    'parent_source' => $this->source->getId(),
                    'type' => $source->getType(),
                    'source' => $source->getId(),
                    'value' => 1,
                ),
            ),
        );
        return $fields;
    }
1324642
protected function getFreshMigrations($source, $destination)
	{
		$me = $this;

		return array_filter($this->getPackageMigrations($source), function($file) use ($me, $destination)
		{
			return ! $me->migrationExists($file, $destination);
		});
	}
776309
public function findSources(string $sources): array
  {
    $patterns = $this->sourcesToPatterns($sources);

    $sources = [];
    foreach ($patterns as $pattern)
    {
      $tmp     = $this->findSourcesInPattern($pattern);
      $sources = array_merge($sources, $tmp);
    }

    $sources = array_unique($sources);
    sort($sources);

    return $sources;
  }