Match the hero image if there's one and assign it to this object

@param array $heroImgData JSON data from Hail
163550
protected function processHeroImage($heroImgData)
    {
        if ($heroImgData) {
            $hero = Image::get()->filter(['HailID' => $heroImgData['id']])->first();
            if (!$hero) {
                $hero = new Image();
            }
            $hero->OrganisationID = $this->OrganisationID;
            $hero->HailOrgID = $this->HailOrgID;
            $hero->HailOrgName = $this->HailOrgName;

            $hero->importHailData($heroImgData);
            $hero = $hero->ID;
        } else {
            $hero = null;
        }

        $this->HeroImageID = $hero;
    }
501691
public function match(array $data): bool
    {
        $match = parent::match($data);
        if ($match) {
            if ($data['fieldConfig']['config']['foreign_table'] !== 'tx_styleguide_inline_usecombination_mm'
                && $data['fieldConfig']['config']['foreign_table'] !== 'tx_styleguide_inline_usecombinationbox_mm'
            ) {
                $match = false;
            }
        }
        return $match;
    }
441479
private boolean matchletMagicCompareOr(int nMatchlets, int firstMatchletOffset, byte[] data) {
        for (int i = 0, matchletOffset = firstMatchletOffset; i < nMatchlets; i++, matchletOffset += 32) {
            if (matchletMagicCompare(matchletOffset, data)) {
                return true;
            }
        }

        return false;
    }
1010672
public function setBackgroundImage(string $imageData) : void
    {
        $url = $this->uploadImage('communityBackgroundImage', $imageData);

        $this->set([
            'backgroundImage' => [
                'sourceUrl' => $url
            ]
        ]);
    }
22900
public function setImage(string $imageData) : void
    {
        $url = $this->uploadImage('communityProfileImage', $imageData);

        $this->set([
            'profileImage' => [
                'sourceUrl' => $url
            ]
        ]);
    }
236353
function ImageSVG($data)
	{
		$data = preg_replace('/^.*?<svg([> ])/is', '<svg\\1', $data); // mPDF 5.7.4
		$data = preg_replace('/<!--.*?-->/is', '', $data); // mPDF 5.7.4

		// Converts < to &lt; when not a tag
		$data = preg_replace('/<([^!?\/a-zA-Z_:])/i', '&lt;\\1', $data); // mPDF 5.7.4

		if ($this->mpdf->svgAutoFont) {
			$data = $this->markScriptToLang($data);
		}

		$this->svg_info = [];
		$last_gradid = ''; // mPDF 6
		$last_svg_fontid = ''; // mPDF 6
		$last_svg_fontdefw = ''; // mPDF 6
		$last_svg_fontstyle = ''; // mPDF 6

		if (preg_match('/<!ENTITY/si', $data)) {
			// Get User-defined entities
			preg_match_all('/<!ENTITY\s+([a-z]+)\s+\"(.*?)\">/si', $data, $ent);
			// Replace entities
			for ($i = 0; $i < count($ent[0]); $i++) {
				$data = preg_replace('/&' . preg_quote($ent[1][$i], '/') . ';/is', $ent[2][$i], $data);
			}
		}

		if (preg_match('/xlink:href\s*=/si', $data)) {

			// GRADIENTS
			// Get links
			preg_match_all('/(<(linearGradient|radialgradient)[^>]*)xlink:href\s*=\s*["\']#(.*?)["\'](.*?)\/>/si', $data, $links);
			if (count($links[0])) {
				$links[5] = [];
			}

			// Delete links from data - keeping in $links
			for ($i = 0; $i < count($links[0]); $i++) {
				$links[5][$i] = 'tmpLink' . random_int(100000, 9999999);
				$data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', '<MYLINKS' . $links[5][$i] . '>', $data);
			}

			// Get targets
			preg_match_all('/<(linearGradient|radialgradient)([^>]*)id\s*=\s*["\'](.*?)["\'](.*?)>(.*?)<\/(linearGradient|radialgradient)>/si', $data, $m);
			$targets = [];
			$stops = [];

			// keeping in $targets
			for ($i = 0; $i < count($m[0]); $i++) {
				$stops[$m[3][$i]] = $m[5][$i];
			}

			// Add back links this time as targets (gradients)
			for ($i = 0; $i < count($links[0]); $i++) {
				$def = $links[1][$i] . ' ' . $links[4][$i] . '>' . $stops[$links[3][$i]] . '</' . $links[2][$i] . '>';
				$data = preg_replace('/<MYLINKS' . $links[5][$i] . '>/is', $def, $data);
			}

			// mPDF 5.7.4
			// <TREF>
			preg_match_all('/<tref ([^>]*)xlink:href\s*=\s*["\']#([^>]*?)["\']([^>]*)\/>/si', $data, $links);
			for ($i = 0; $i < count($links[0]); $i++) {
				// Get the item to use from defs
				$insert = '';
				if (preg_match('/<text [^>]*id\s*=\s*["\']' . $links[2][$i] . '["\'][^>]*>(.*?)<\/text>/si', $data, $m)) {
					$insert = $m[1];
				}
				if ($insert) {
					$data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', $insert, $data);
				}
			}

			// mPDF 5.7.2
			// <USE>
			preg_match_all('/<use( [^>]*)xlink:href\s*=\s*["\']#([^>]*?)["\']([^>]*)\/>/si', $data, $links);
			for ($i = 0; $i < count($links[0]); $i++) {
				// Get the item to use from defs
				$insert = '';
				if (preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']' . $links[2][$i] . '["\'][^>]*\/>/si', $data, $m)) {
					$insert = $m[0];
				}
				if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']' . $links[2][$i] . '["\']/si', $data, $m)) {
					if (preg_match('/<' . $m[1] . '[^>]*id\s*=\s*["\']' . $links[2][$i] . '["\'][^>]*>.*?<\/' . $m[1] . '>/si', $data, $m)) {
						$insert = $m[0];
					}
				}

				if ($insert) {
					$inners = $links[1][$i] . ' ' . $links[3][$i];

					// Change x,y coords to translate()
					if (preg_match('/\sy\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {
						$y = $m[1];
					} else {
						$y = 0;
					}

					if (preg_match('/\sx\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {
						$x = $m[1];
					} else {
						$x = 0;
					}

					if ($x || $y) {

						$inners = preg_replace('/(y|x)\s*=\s*["\']([^>]*?)["\']/', '', $inners);
						if (preg_match('/transform\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {

							if (preg_match('/translate\(\s*([0-9\.]+)\s*,\s*([0-9\.]+)\s*\)/', $m[1], $mm)) {
								$transform = $m[1]; // transform="...."
								$x += $mm[1];
								$y += $mm[2];
								$transform = preg_replace('/' . preg_quote($mm[0], '/') . '/', '', $transform);
								$transform = 'transform="' . $transform . ' translate(' . $x . ', ' . $y . ')"';
								$inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', $transform, $inners);
							} else {
								$inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', 'transform="' . $m[1] . ' translate(' . $x . ', ' . $y . ')"', $inners);
							}

						} else {
							$inners .= ' transform="translate(' . $x . ', ' . $y . ')"';
						}
					}
				}

				$replacement = '<g ' . $inners . '>' . $insert . '</g>';
				$data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', $replacement, $data);
			}

			preg_match_all('/<use( [^>]*)xlink:href\s*=\s*["\']#([^>]*?)["\']([^>]*)>\s*<\/use>/si', $data, $links);
			for ($i = 0; $i < count($links[0]); $i++) {

				// Get the item to use from defs
				$insert = '';
				if (preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']' . $links[2][$i] . '["\'][^>]*\/>/si', $data, $m)) {
					$insert = $m[0];
				}

				if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id\s*=\s*["\']' . $links[2][$i] . '["\']/si', $data, $m)) {
					if (preg_match('/<' . $m[1] . '[^>]*id\s*=\s*["\']' . $links[2][$i] . '["\'][^>]*>.*?<\/' . $m[1] . '>/si', $data, $m)) {
						$insert = $m[0];
					}
				}

				if ($insert) {
					$inners = $links[1][$i] . ' ' . $links[3][$i];

					// Change x,y coords to translate()
					if (preg_match('/\sy\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {
						$y = $m[1];
					} else {
						$y = 0;
					}

					if (preg_match('/\sx\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {
						$x = $m[1];
					} else {
						$x = 0;
					}

					if ($x || $y) {
						$inners = preg_replace('/(y|x)\s*=\s*["\']([^>]*?)["\']/', '', $inners);
						if (preg_match('/transform\s*=\s*["\']([^>]*?)["\']/', $inners, $m)) {
							if (preg_match('/translate\(\s*([0-9\.]+)\s*,\s*([0-9\.]+)\s*\)/', $m[1], $mm)) {
								$transform = $m[1]; // transform="...."
								$x += $mm[1];
								$y += $mm[2];
								$transform = preg_replace('/' . preg_quote($mm[0], '/') . '/', '', $transform);
								$transform = 'transform="' . $transform . ' translate(' . $x . ', ' . $y . ')"';
								$inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', $transform, $inners);
							} else {
								$inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', 'transform="' . $m[1] . ' translate(' . $x . ', ' . $y . ')"', $inners);
							}
						} else {
							$inners .= ' transform="translate(' . $x . ', ' . $y . ')"';
						}
					}

					$replacement = '<g ' . $inners . '>' . $insert . '</g>';
					$data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', $replacement, $data);
				}
			}
		}

		// Removes <pattern>
		$data = preg_replace('/<pattern.*?<\/pattern>/is', '', $data);

		// Removes <marker>
		$data = preg_replace('/<marker.*?<\/marker>/is', '', $data);

		$this->svg_info['data'] = $data;
		$this->svg_string = '';

		$svg2pdf_xml = '';

		// Don't output stuff inside <defs>
		$this->inDefs = false;

		$svg2pdf_xml_parser = xml_parser_create("utf-8");

		xml_parser_set_option($svg2pdf_xml_parser, XML_OPTION_CASE_FOLDING, false);

		xml_set_element_handler(
			$svg2pdf_xml_parser,
			[$this, 'xml_svg2pdf_start'],
			[$this, 'xml_svg2pdf_end']
		);

		xml_set_character_data_handler(
			$svg2pdf_xml_parser,
			[$this, 'characterData']
		);

		xml_parse($svg2pdf_xml_parser, $data);

		if ($this->svg_error) {
			return false;
		} else {
			return [
				'x' => $this->svg_info['x'] * $this->kp,
				'y' => -$this->svg_info['y'] * $this->kp,
				'w' => $this->svg_info['w'] * $this->kp,
				'h' => -$this->svg_info['h'] * $this->kp,
				'data' => $this->svg_string,
			];
		}
	}
810571
public static function ltiLinkUrl($postdata=false) {
        if ( $postdata === false ) $postData = $_POST;
        if ( ! isset($postdata['content_item_return_url']) ) return false;
        if ( isset($postdata['accept_media_types']) ) {
            $ltilink_mimetype = 'application/vnd.ims.lti.v1.ltilink';
            $m = new Mimeparse;
            $ltilink_allowed = $m->best_match(array($ltilink_mimetype), $postdata['accept_media_types']);
            if ( $ltilink_mimetype != $ltilink_allowed ) return false;
            return $postdata['content_item_return_url'];
        }
        return false;
    }
607446
public function jsonUnSerialize(\SwaggerValidator\Common\Context $context, $jsonData)
    {
        if (!is_object($jsonData)) {
            $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
        }

        if (!($jsonData instanceof \stdClass)) {
            $context->throwException('Mismatching type of JSON Data received', __METHOD__, __LINE__);
        }

        foreach (get_object_vars($jsonData) as $key => $value) {

            if ($key == \SwaggerValidator\Common\FactorySwagger::KEY_DEFINITIONS) {
                continue;
            }

            $value      = $this->extractNonRecursiveReference($context, $value);
            $this->$key = \SwaggerValidator\Common\FactorySwagger::getInstance()->jsonUnSerialize($context->setDataPath($key), $this->getCleanClass(__CLASS__), $key, $value);
        }

        \SwaggerValidator\Common\CollectionReference::getInstance()->unserializeReferenceDefinitions($context);
        \SwaggerValidator\Common\CollectionReference::getInstance()->unserializeReferenceDefinitions($context);
        \SwaggerValidator\Common\CollectionReference::getInstance()->cleanReferenceDefinitions($context);
        \SwaggerValidator\Common\CollectionReference::getInstance()->jsonUnSerialize($context);

        $context->logDecode(get_class($this), __METHOD__, __LINE__);
    }
70902
function mimeTypeSetting( $mimeData )
    {
        if ( !isset( $this->MIMETypeSettingsMap[$mimeData['name']] ) )
            return false;
        $list = $this->MIMETypeSettingsMap[$mimeData['name']];
        foreach ( $list as $item )
        {
            if ( is_array( $item['match'] ) )
            {
                if ( array_key_exists( 'info', $mimeData ) && is_array( $mimeData['info'] ) )
                {
                    $isMatch = true;
                    $info = $mimeData['info'];
                    foreach ( $item['match'] as $matchKey => $matchValue )
                    {
                        if ( !isset( $info[$matchKey] ) or
                             $info[$matchKey] != $matchValue )
                        {
                            $isMatch = false;
                            break;
                        }
                    }
                    if ( $isMatch )
                        return $item;
                }
            }
            else
                return $item;
        }
        return false;
    }
561104
protected function parseSupraImage(ImageReferencedElement $imageData)
	{
		$imageId = $imageData->getImageId();

		$fileStorage = $this->container['cms.file_storage'];
		/* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */

		$image = $fileStorage->findImage($imageId);

		if ($image === null) {
			return null;
		}

		$sizeName = $imageData->getSizeName();

		$size = $image->findImageSize($sizeName);

		if ($size === null) {
			$this->container->getLogger()->warn("Image [{$imageId}] size [{$sizeName}] not found.");
			return null;
		}

		$tag = new HtmlTag('img');

		if ($size->isCropped()) {
			$width = $size->getCropWidth();
			$height = $size->getCropHeight();
		} else {
			$width = $size->getWidth();
			$height = $size->getHeight();
		}

		$src = $fileStorage->getWebPath($image, $size);

		$tag->setAttribute('src', $src);

		$align = $imageData->getAlign();
		if (!empty($align)) {
			if ($align === 'left') {
				$tag->addClass('pull-left');
			} else if ($align === 'right') {
				$tag->addClass('pull-right');
			} else if ($align === 'center') {
				$tag->addClass('center-block');
				$tag->setAttribute('style', "width: {$width}px;");
			}
		}

		if (!empty($width)) {
			$tag->setAttribute('width', $width);
		}

		if (!empty($height)) {
			$tag->setAttribute('height', $height);
		}

		$title = trim($imageData->getTitle());
		if (!empty($title)) {
			$tag->setAttribute('title', $title);
		}

		$tag->setAttribute('alt', trim($imageData->getAlternateText()));

		return $tag;
	}
1304779
private function parseYaml($fileData)
    {
        return Yaml::parse(
            $fileData,
            Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE | Yaml::PARSE_OBJECT | Yaml::PARSE_CUSTOM_TAGS
        );
    }
306664
private function matchRequest(&$classData)
    {
        if (!is_array($classData)) {
            throw new RestException("Invalid class cache data.");
        }

        // build the request url upon which we will do the matching
        try {
            $url = $this->getUrl();
        } catch (\Exception $e) {
            throw $e;
        }


        // get request method
        $method = $this->getMethod();
        if (!in_array($method, self::$supportedRequestTypes)) {
            throw new RestException('Unsupported request method: "' . $method . '"');
        }

        $callbacks = (empty($classData[$method])) ? [] : $classData[$method];

        // match array
        $matchedMethod = [
            'methodData'        => false,
            'matchedParameters' => false
        ];

        // validate that we have the ending class name in the url
        $classUrl = PathTransformations::classNameToUrl($this->class, $this->normalize);
        if (strpos($url, '/' . $classUrl . '/') !== false) {
            $matchedMethod = $this->matchMethod($callbacks, $url);

            // if method was not matched
            if (!$matchedMethod['methodData']) {
                // if no method was matched, let's try to match a default method
                $matchedMethod = $this->matchDefaultMethod($callbacks, $url, $classUrl);
            }
        }

        $methodData = (isset($matchedMethod['methodData'])) ? $matchedMethod['methodData'] : false;
        $matchedParameters = ($matchedMethod['matchedParameters']) ? $matchedMethod['matchedParameters'] : [];

        $requestBag = new RequestBag();
        $requestBag->setClassData($classData)
                   ->setMethodData($methodData)
                   ->setMethodParameters($matchedParameters)
                   ->setApi($this->api);

        $callback = new Callback($requestBag);

        return $callback->getCallbackResult();
    }
151326
public static function assert($messageData): void
    {
        Assertion::isArray($messageData, 'MessageData must be an array');
        Assertion::keyExists($messageData, 'message_name', 'MessageData must contain a key message_name');
        Assertion::keyExists($messageData, 'uuid', 'MessageData must contain a key uuid');
        Assertion::keyExists($messageData, 'payload', 'MessageData must contain a key payload');
        Assertion::keyExists($messageData, 'metadata', 'MessageData must contain a key metadata');
        Assertion::keyExists($messageData, 'created_at', 'MessageData must contain a key created_at');

        self::assertMessageName($messageData['message_name']);
        self::assertUuid($messageData['uuid']);
        self::assertPayload($messageData['payload']);
        self::assertMetadata($messageData['metadata']);
        self::assertCreatedAt($messageData['created_at']);
    }
1326078
protected function createObject($oData, $bReturnObject = false)
    {
        $aData = [
            'bucket_id'        => $oData->bucket->id,
            'filename'         => $oData->filename,
            'filename_display' => $oData->name,
            'mime'             => $oData->mime,
            'filesize'         => $oData->filesize,
            'md5_hash'         => $oData->md5_hash,
            'driver'           => $this->oEnabledDriver->slug,
        ];

        // --------------------------------------------------------------------------

        if (isset($oData->img->width) && isset($oData->img->height) && isset($oData->img->orientation)) {
            $aData['img_width']       = $oData->img->width;
            $aData['img_height']      = $oData->img->height;
            $aData['img_orientation'] = $oData->img->orientation;
        }

        // --------------------------------------------------------------------------

        //  Check whether file is animated gif
        if ($oData->mime == 'image/gif') {
            if (isset($oData->img->is_animated)) {
                $aData['is_animated'] = $oData->img->is_animated;
            } else {
                $aData['is_animated'] = false;
            }
        }

        // --------------------------------------------------------------------------

        $oObjectModel = Factory::model('Object', 'nails/module-cdn');
        $iObjectId    = $oObjectModel->create($aData);

        if ($iObjectId) {
            return $bReturnObject ? $this->getObject($iObjectId) : $iObjectId;
        } else {
            return false;
        }
    }
20620
public function match($sourceImage) : GD
    {
        if( ! is_resource($sourceImage) )
        {
            throw new InvalidArgumentException(NULL, '[resource]');
        }

        imagecolormatch($this->canvas, $sourceImage);

        return $this;
    }
497147
public function match($data)
    {
        $match = false;
        $operator = $this->getOperator();

        foreach ($this->getFilters() as $filter) {
            $match = $filter->match($data);

            if ((!$match && $operator === self::LOGICAL_AND)
                || ($match && $operator === self::LOGICAL_OR)
            ) {
                break;
            }
        }

        return $match;
    }
393565
public static function encode($jsonData)
    {
        $jsonString = json_encode($jsonData);
        // 5.5.0 	The return value on failure was changed from null string to FALSE.
        if (false === $jsonString || 'null' === $jsonString) {
            throw new JsonException('unable to encode JSON');
        }

        return $jsonString;
    }