Check if directory of file resource is trusted.

@param  string $filepath

@return boolean         true if directory is trusted
@throws SmartyException if PHP directory is not trusted
344011
public function isTrustedPHPDir($filepath)
    {
        if (empty($this->trusted_dir)) {
            throw new SmartyException("directory '{$filepath}' not allowed by security setting (no trusted_dir specified)");
        }

        // check if index is outdated
        if (!$this->_trusted_dir || $this->_trusted_dir !== $this->trusted_dir) {
            $this->_php_resource_dir = array();

            $this->_trusted_dir = $this->trusted_dir;
            foreach ((array) $this->trusted_dir as $directory) {
                $directory = $this->smarty->_realpath($directory . DS, true);
                $this->_php_resource_dir[$directory] = true;
            }
        }

        $this->_php_resource_dir = $this->_checkDir($this->smarty->_realpath($filepath, true), $this->_php_resource_dir);
        return true;
    }
996076
public function archive($filepath)
	{
		if ( ! ($fp = @fopen($filepath, 'w+b')))
		{
			return FALSE;
		}

		flock($fp, LOCK_EX);

		for ($result = $written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result)
		{
			if (($result = fwrite($fp, substr($data, $written))) === FALSE)
			{
				break;
			}
		}

		flock($fp, LOCK_UN);
		fclose($fp);

		return is_int($result);
	}
734005
protected function isLockExpired(FilePath $lockPath)
    {
        $expired = time() > $this->getLockExpiry($lockPath);
        if ($expired) {
            $this->removeLockFile($lockPath);
        }

        return $expired;
    }
1069217
public function loadFile($filepath)
    {
        $file = realpath($filepath);
        if ($file === false) {
            throw new JitException("Error, the file `'{$filepath}'` doesn't exist.");
        }
        if ($cached = $this->cached($file)) {
            require $cached;
            return true;
        }
        $code = file_get_contents($file);
        $timestamp = filemtime($file);

        $rewrited = $this->_patchers->process($code, $file);
        $cached = $this->cache($file, $rewrited, max($timestamp, $this->_watchedTimestamp) + 1);
        require $cached;
        return true;
    }
137410
public function compressFile (string $filePath) : bool
    {
        $compressor = $this->getCompressor();

        if (null === $compressor)
        {
            return false;
        }

        $process = new Process(\array_merge($compressor, [$filePath]));
        $process->run();
        return $process->isSuccessful();
    }
619165
public static function parse(string $filePath): FilePathInterface
    {
        if (!self::myFilePathParse(
            DIRECTORY_SEPARATOR,
            $filePath,
            function ($p, $d, &$e) {
                return self::myPartValidator($p, $d, $e);
            },
            null,
            $isAbsolute,
            $aboveBaseLevel,
            $drive,
            $directoryParts,
            $filename,
            $error)
        ) {
            throw new FilePathInvalidArgumentException('File path "' . $filePath . '" is invalid: ' . $error);
        }

        return new self($isAbsolute, $aboveBaseLevel, $drive, $directoryParts, $filename);
    }
1019639
public static function providers(string $filePath = null)
    {
        if (is_file($filePath)) {
            /** @noinspection PhpIncludeInspection */
            $providers = require_once $filePath;

            $providers = is_array($providers) ? $providers : [];

            IOC::addProviders($providers);

            Event::dispatch('minimal.loaded.providers',
                [$filePath, $providers]);
        }
    }
1019773
public function ensureSymlinkExists($sourcePath, $symlinkPath)
    {
        if (!is_link($symlinkPath)) {
            $this->ensureDirectoryExists(dirname($symlinkPath));

            return symlink($sourcePath, $symlinkPath);
        }

        return false;
    }
762866
public static function unlinkSafe(string $filePath) : bool
    {
        if (!FileHelper::fileExistsSafe($filePath)) {
            return false;
        }

        if (DirHelper::isDirSafe($filePath)) {
            return false;
        }

        return unlink($filePath);
    }
1306447
protected function safeFileExists($sFilePath)
    {
        if (!is_string($sFilePath)) {
            throw new \InvalidArgumentException('Argument "$sFilePath" expects a string, "' . (is_object($sFilePath) ? get_class($sFilePath) : gettype($sFilePath)) . '" given');
        }

        // Retrieve "open_basedir" restriction
        if ($this->openBaseDirPaths === null) {
            if ($sOpenBaseDir = ini_get('open_basedir')) {
                $this->openBaseDirPaths = explode(PATH_SEPARATOR, $sOpenBaseDir);
            } else {
                $this->openBaseDirPaths = array();
            }
        }

        if (!$this->openBaseDirPaths) {
            return file_exists($sFilePath);
        }
        foreach ($this->openBaseDirPaths as $sAllowedPath) {
            if (strpos($sFilePath, $sAllowedPath)) {
                return file_exists($sFilePath);
            }
        }
        return false;
    }
813533
public function obfuscateDirectory(string $path) : bool
    {
        $this->plain_path = rtrim($path, "/");
        if (is_dir($this->plain_path) === false) {
            $this->addErrorMessage("The specified directory does not exist");
            return false;
        }

        if (is_readable($this->plain_path) == false) {
            $this->addErrorMessage("No permissions to read directory");
            return false;
        }

        if ($this->isObfuscatedDirectory($this->plain_path) == true) {
            $this->addRuntimeMessage("The specified directory is already obfuscated");
            return false;
        }

        return true;
    }
216653
public function isFile($path)
    {
        $metadata = $this->dropbox->getMetadata($this->pathRoot.$path);
        return is_array($metadata) && isset($metadata['is_dir']) && $metadata['is_dir']==false;
    }
11390
private static function isMessageHandler(string $filePath): bool
    {
        $fileContent = \file_get_contents($filePath);

        if (false !== $fileContent)
        {
            return false !== \strpos($fileContent, '@CommandHandler') ||
                false !== \strpos($fileContent, '@EventListener');
        }

        throw new \LogicException(
            \sprintf('Error loading "%s" file contents', $filePath)
        );
    }
463617
private function isInternalRoute($filepath)
    {
        foreach ($this->internalRouteDirPattern as $pattern) {
            if (preg_match($pattern, $filepath)) {
                return true;
            }
        }

        $filename = basename($filepath);
        foreach ($this->internalRouteFilePattern as $pattern) {
            if (preg_match($pattern, $filename)) {
                return true;
            }
        }

        return false;
    }
1072666
public function checkCreateFile($filePath)
    {
        $defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();

        if (file_exists($filePath)) {
            if (!is_writable($filePath) && !in_array($this->getPermissionUtils()->getCurrentPermission($filePath), array($defaultPermissions['file'], $defaultPermissions['dir']))) {
                return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
            }
            return true;
        }

        $pathParts = pathinfo($filePath);
        if (!file_exists($pathParts['dirname'])) {
            $dirPermission = $defaultPermissions['dir'];
            $dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission;

            if (!$this->mkdir($pathParts['dirname'], $dirPermission, true)) {
                throw new Error('Permission denied: unable to create a folder on the server - ' . $pathParts['dirname']);
            }
        }

        if (touch($filePath)) {
            return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
        }

        return false;
    }
1359576
public function isDir($directory)
    {
        $pwd = $this->ftp->pwd();

        if ($pwd === false) {
            throw new FtpException('Unable to resolve the current directory');
        }

        if (@$this->ftp->chdir($directory)) {
            $this->ftp->chdir($pwd);
            return true;
        }

        $this->ftp->chdir($pwd);

        return false;
    }
201643
protected function buildDirectory($filePath)
	{
		$directory = dirname($filePath);
		
		if (!is_dir($directory)) {
			mkdir($directory, 0777, true);
		}
	}