Validate target

@param $target

@return bool
@throws \Fei\Entity\Validator\Exception
517163
public function validateTarget($target)
    {
        if ($target instanceof Application) {
            $validator = new ApplicationValidator();
            $response = $validator->validate($target);
        } elseif ($target instanceof ApplicationGroup) {
            $validator = new ApplicationGroupValidator();
            $response = $validator->validate($target);
        } else {
            $this->addError('target', 'Target must be a valid instance of Application or ApplicationGroup');
            return false;
        }

        if (!$response) {
            $this->addError('target', 'Target must be a valid instance of Application or ApplicationGroup class - ' . $validator->getErrorsAsString());
        }

        return $response;
    }
1350373
private function findTargetCompiler($target, $mode): CompilationTarget
    {
        /** @var CompilationTarget $targetCompiler */
        foreach ($this->compilationTargets as $targetCompiler) {
            if ($targetCompiler->supports($target, $mode)) {
                return $targetCompiler;
            }
        }

        throw new TargetUnsupportedException('The given target is not supported.');
    }
1297367
public function php(string $target)
    {
        $php = new PHP();
        $php->process($this->coverage, $target);
    }
215060
public function extend($target)
    {
        if (!$target || is_scalar($target)) {
            $target = [];
        }

        $args = func_get_args();
        $isArr = is_array($target) || $target instanceof \ArrayAccess;
        $isObj = !$isArr && is_object($target);

        foreach ($args as $obj) {
            if (!$obj || (!is_array($obj) && !is_object($obj))) {
                continue;
            }
            $obj = $obj instanceof \Iterator ? $obj : (array)$obj;
            foreach ($obj as $k => $v) {
                if ($isArr) {
                    $target[$k] = $v;
                } elseif ($isObj) {
                    $target->$k = $v;
                } else {
                    // skip
                }
            }
        }

        return $target;
    }
1039062
public function setTarget( $target ) {
		$this->target = is_string( $target ) ? $target : null;

		if ( $this->target !== null ) {
			$this->button->setAttributes( [ 'target' => $target ] );
		} else {
			$this->button->removeAttributes( [ 'target' ] );
		}

		return $this;
	}
1273415
public function setTarget($target)
    {
        if (!is_string($target) || $target == '') {
            throw new \InvalidArgumentException('No valid URL given.');
        }

        $this->target = $target;

        // Set meta refresh content if header location is ignored
        $this->setContent(
            sprintf('<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0; url=%1$s" />
    </head>
    <body>
        <p>Redirecting to <a href="%1$s">%1$s</a>.
    </body>
</html>', htmlspecialchars($target, ENT_QUOTES, 'UTF-8')));

        // Set header location
        $this->setHeader('Location', $target);

        return $this;
    }
932560
public function mapTarget(PersistenceTarget $target): Target
    {
        try {
            $targetType = $this->targetTypeRegistry->getTargetType(
                $target->type
            );
        } catch (TargetTypeException $e) {
            $targetType = new NullTargetType();
        }

        $targetData = [
            'id' => $target->id,
            'status' => $target->status,
            'ruleId' => $target->ruleId,
            'targetType' => $targetType,
            'value' => $target->value,
        ];

        return Target::fromArray($targetData);
    }
26318
public function Target($Target = FALSE) {
      if ($Target === FALSE) {
         $Target = $this->Form->GetFormValue('Target', FALSE);
         if (!$Target)
            $Target = $this->Request->Get('Target', '/');
      }
      
      // Make sure that the target is a valid url.
      if (!preg_match('`(^https?://)`', $Target)) {
         $Target = '/'.ltrim($Target, '/');
         
         // Never redirect back to signin.
         if (preg_match('`^/entry/signin`i', $Target))
            $Target = '/';
      } else {
         $MyHostname = parse_url(Gdn::Request()->Domain(),PHP_URL_HOST);
         $TargetHostname = parse_url($Target, PHP_URL_HOST);
         
         // Only allow external redirects to trusted domains.
         $TrustedDomains = C('Garden.TrustedDomains', TRUE);
         
         if (is_array($TrustedDomains)) {
            // Add this domain to the trusted hosts.
            $TrustedDomains[] = $MyHostname;
            $Sender->EventArguments['TrustedDomains'] = &$TrustedDomains;
            $this->FireEvent('BeforeTargetReturn');
         }
			
         if ($TrustedDomains === TRUE) {
            return $Target;
			} elseif (count($TrustedDomains) == 0) {
				// Only allow http redirects if they are to the same host name.
				if ($MyHostname != $TargetHostname)
					$Target = '';
			} else {
				// Loop the trusted domains looking for a match
				$Match = FALSE;
				foreach ($TrustedDomains as $TrustedDomain) {
					if (StringEndsWith($TargetHostname, $TrustedDomain, TRUE))
						$Match = TRUE;
				}
				if (!$Match)
					$Target = '';
			}
      }
      return $Target;
   }
141643
public function extract($target)
		{
			if (true === $this->_enabled && !empty($target)) {
				return $this->_zip->extractTo($target);
			}

			return false;
		}
1241543
public function run($target)
    {
        $return = $this->exec($this->getCommand($target));
        return $this->output[$target] = $this->cleanOutput($target, $return['output']);
    }
184654
public function equals($target) {
		return $target instanceof self &&
			$this->languageCode === $target->languageCode &&
			$this->sentenceTree->equals($target->sentenceTree) &&
			$this->measures == $target->measures;
	}
841143
public function setTarget($target = null)
        {
            if (null !== $target && !is_string($target)) {
                throw new Exception(
                        'Invalid argument: $target must be a string or null');
            }

            $this->_target = $target;

            return $this;
        }
680426
public function setTarget($target)
    {
        //Add to route group if any
        if (!$target instanceof \Closure) {
            $groupNamespace = implode('\\', Router::$groupsProps['namespace']);
            $target = $groupNamespace ? "$groupNamespace\\$target" : $target;
        }

        if (!$target instanceof Closure &&
                !preg_match(Router::TARGET_REGEX, $target)) {
            throw new Exception("Invalid target string $target");
        }
        $this->target = $target;

        return $this;
    }
204950
public function equals( $target ) {
		if ( $target === $this ) {
			return true;
		}

		if ( !( $target instanceof self ) ) {
			return false;
		}

		return $this->isAssociative === $target->isAssociative
			&& $this->getArrayCopy() == $target->getArrayCopy();
	}
621078
private function identifyRequest($target = false)
    {
        $retval = false;

        $this->locateURI();

        $nb_engine = CNabuEngine::getEngine();

        if ($target) {
            $temp_target = CNabuSiteTarget::findByURL($this->nb_site, $this->page_uri);
            if ($temp_target instanceof CNabuSiteTarget && $temp_target->isValueNumeric('nb_language_id')) {
                $nb_language = new CNabuLanguage($temp_target);
                if ($nb_language->isFetched()) {
                    $this->nb_language = $nb_language;
                } else {
                    $this->nb_language = $this->nb_site->getDefaultLanguage();
                }
            }

            if (!($target instanceof CNabuSiteTarget) &&
                is_numeric($nb_site_target_id = nb_getMixedValue($target, 'nb_site_target_id'))
            ) {
                $target = new CNabuSiteTarget($nb_site_target_id);
                if ($target->isFetched()) {
                    $this->nb_site_target = $target;
                }
            } else {
                $this->nb_site_target = $target;
            }
            if ($this->nb_site_target instanceof CNabuSiteTarget &&
                $this->nb_language === null && $this->nb_site_target->isValueNumeric('nb_language_id')) {
                $this->nb_language = new CNabuLanguage($this->nb_site_target->getValue('nb_language_id'));
                if ($this->nb_language->isNew()) {
                    $this->nb_language = null;
                }
            }
            if ($this->nb_language === null) {
                $this->nb_language = $this->nb_site->getDefaultLanguage();
            }
            if ($this->nb_site_target !== null &&
                $this->nb_language !== null &&
                $this->nb_site_target->hasTranslation($this->nb_language)
            ) {
                $this->nb_response->setHTTPResponseCode(200);
                $nb_engine->traceLog('Page Status', 'Found');

                $retval = true;
            }
        } elseif ($this->findTargetByURL($this->page_uri)) {
            $nb_engine->traceLog("Page ID", $this->nb_site_target->getId());

            if ($this->nb_language === null) {
                throw new ENabuCoreException(ENabuCoreException::ERROR_LANGUAGE_NOT_FOUND_FOR_PAGE_URI);
            }
            $nb_engine->traceLog("Page language", $this->nb_language->getISO6391());
            $nb_engine->traceLog('Page Status', 'Found');

            $retval = true;
        }

        if (!($this->nb_site_target instanceof CNabuSiteTarget) || !$retval) {
            $nb_engine->traceLog('Page Status', 'Not found');
            $link = $this->nb_site->getPageNotFoundTargetLink();
            if ($link->isLinkable()) {
                if ($link->isTranslatedTarget()) {
                    $this->nb_language = $this->nb_site->getDefaultLanguage();
                    if ($this->nb_language instanceof CNabuLanguage &&
                        ($nb_site_target = $link->getTranslatedObject()) instanceof CNabuSiteTarget &&
                        ($nb_site_target->getTranslation($this->nb_language) instanceof CNabuSiteTargetLanguage)
                    ) {
                        $this->nb_site_target = $nb_site_target;
                        $retval = true;
                    }
                }
            }

            if ($this->nb_response->getHTTPResponseCode() === 0) {
                $this->nb_response->setHTTPResponseCode(404);
            }
        }

        return $retval;
    }
642858
public function moveTo(string $target): ?string
    {
        $ret = $this->handle->rpoplpush($this->name, $target);
        return (false === $ret) ? null : $ret;
    }
220177
public function copy($target) {
        if (!file_exists(dirname($target)))
            if (!mkdir(dirname($target), 0777, true))
                return false;
        return true;
    }