Checks that target directory is valid. Asks questions in tricky cases.
@param string $target
@return bool|string
505323
protected function normalizeTargetDir($target)
    {
        $target = rtrim(Yii::getAlias($target), '\\/');
        if (file_exists($target)) {
            if (is_dir($target) && !$this->confirm('TargetDirectory already exists. Overwrite?', true)) {
                $this->stderr('User aborted.' . PHP_EOL);

                return false;
            }
            if (is_file($target)) {
                $this->stderr("Error: Target directory \"$target\" is a file!" . PHP_EOL);

                return false;
            }
        } else {
            mkdir($target, 0777, true);
        }

        return $target;
    }
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;
    }
642858
public function moveTo(string $target): ?string
    {
        $ret = $this->handle->rpoplpush($this->name, $target);
        return (false === $ret) ? null : $ret;
    }
317587
public function contains($targetName)
    {
        if (InstallTarget::DEFAULT_TARGET === $targetName) {
            return null !== $this->defaultTarget;
        }

        return isset($this->targets[$targetName]);
    }
1326044
public function equals($target): bool
    {
        if (
            ($this instanceof RoleInterface && $target instanceof RoleInterface) ||
            ($this instanceof SceneInterface && $target instanceof SceneInterface)
        ) {
            return $this->getType() === $target->getType() &&
                $this->getId() === $target->getId();
        }

        return false;
    }
860573
private function _hasMatchingTarget(Targets $targets): bool
    {
        foreach ($this->_config->targets() as $target) {
            if ($targets->hasTarget($target)) {
                return true;
            }
        }
        return false;
    }
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;
    }
487397
public static function merge( $target )
    {
        $_arrays = static::clean( func_get_args() );
        $_target = static::clean( array_shift( $_arrays ) );

        foreach ( $_arrays as $_array )
        {
            $_target = array_merge(
                $_target,
                static::clean( $_array )
            );

            unset( $_array );
        }

        unset( $_arrays );

        return $_target;
    }
514158
public function directoryExists(string $name)
    {
        if(!$this->_isLoaded) {
            $this->load();
        }

        return in_array($name, $this->_directories);
    }
279039
public function copy($target) {
        if (!parent::copy($target))
            return false;
        return copy($this->fileSource, $target);
    }
1337156
private function link(string $source, string $target): bool
    {
        if (!@link($source, $target)) {
            $message = 'Could not create link.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return true;
    }
424292
private function mkdir($target)
    {
        if (\is_dir($target)) {
            return;
        }

        if (! $this->file->mkdir($target)) {
            $this->output->writeln("<error>[$target] could not be created. Please check directory permissions.</error>");
        }
    }
231915
public static function remove($target)
    {
        if (is_dir($target)) {
            $files = glob($target . '*', GLOB_MARK);
            foreach ($files as $file) {
                self::remove($file);
            }
            @rmdir($target);
        } else {
            if (is_file($target)) {
                @unlink($target);
            }
        }
    }
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;
   }
302530
public function getTargetClass($target): int
    {
        if (!in_array($target, $this->classes, true)) {
            throw new InvalidArgumentException(
                sprintf('Target with value "%s" is not part of the accepted classes', $target)
            );
        }

        return array_search($target, $this->classes, true);
    }
688004
protected function resolveTargetFilePath($target, $basePath)
    {
        switch (true) {

            // resource
            case strpos($target, '@') === 0:
                $targetPath = $this->fileLocator->locate($target);
                break;

            // kernel related
            case strpos($target, '/') === 0:
                $targetPath = sprintf('%s%s',
                    $this->kernelDir,
                    $target
                );
                break;

            // related file
            default:
                $targetPath = sprintf('%s/%s', $basePath, $target);
                break;
        }

        if (!is_writable($targetPath)) {
            throw new \InvalidArgumentException(sprintf(
                'Unable to resolve "%s" target, resolved into "%s" file path which is not writable.',
                $target,
                $targetPath
            ));
        }

        return $targetPath;
    }
462164
protected function symlink($target, $link)
    {
        $fs = FileSystem::getFileSystem();

        if ($this->isRelative()) {
            $link = (new PhingFile($link))->getAbsolutePath();
            $target = rtrim($this->makePathRelative($target, dirname($link)), '/');
        }

        if (is_link($link) && @readlink($link) == $target) {
            $this->log('Link exists: ' . $link, Project::MSG_INFO);

            return true;
        }

        if (file_exists($link) || is_link($link)) {
            if (!$this->getOverwrite()) {
                $this->log('Not overwriting existing link ' . $link, Project::MSG_ERR);

                return false;
            }

            if (is_link($link) || is_file($link)) {
                $fs->unlink($link);
                $this->log('Link removed: ' . $link, Project::MSG_INFO);
            } else {
                $fs->rmdir($link, true);
                $this->log('Directory removed: ' . $link, Project::MSG_INFO);
            }
        }

        $this->log('Linking: ' . $target . ' to ' . $link, Project::MSG_INFO);

        return $fs->symlink($target, $link);
    }