Checks if the current directory is a valid Zephir project.

@throws Exception

@return string
16042
private function checkDirectory()
    {
        $namespace = $this->config->get('namespace');
        if (!$namespace) {
            // TODO: Add more user friendly message.
            // For example assume if the user call the command from the wrong dir
            throw new Exception('Extension namespace cannot be loaded');
        }

        if (!\is_string($namespace)) {
            throw new Exception('Extension namespace is invalid');
        }

        if (!$this->filesystem->isInitialized()) {
            $this->filesystem->initialize();
        }

        if (!$this->filesystem->exists('.')) {
            if (!$this->checkIfPhpized()) {
                $this->logger->info(
                    'Zephir version has changed, use "zephir fullclean" to perform a full clean of the project'
                );
            }

            $this->filesystem->makeDirectory('.');
        }

        return $namespace;
    }
252285
protected function checkProjectName()
    {
        if (is_dir($this->projectDir) && !$this->isEmptyDirectory($this->projectDir)) {
            throw new \RuntimeException(sprintf(
                "There is already a '%s' project in this directory (%s).\n".
                'Change your project name or create it in another directory.',
                $this->projectName, $this->projectDir
            ));
        }

        if ('demo' === $this->projectName && 'new' === $this->getName()) {
            $this->output->writeln("\n <bg=yellow> TIP </> If you want to download the Symfony Demo app, execute 'symfony demo' instead of 'symfony new demo'");
        }

        return $this;
    }
41971
protected function hasCorrectPermissionForUpdate() : bool
    {
        if (! $this->pathToUpdate) {
            throw new \Exception('No directory set for update. Please set the update with: setPathToUpdate(path).');
        }

        $collection = collect($this->pathToUpdate->files())->each(function ($file) { /* @var \SplFileInfo $file */
            if (! File::isWritable($file->getRealPath())) {
                event(new HasWrongPermissions($this));

                return false;
            }
        });

        return true;
    }
824105
public static function isPtySupported()
    {
        static $result;

        if (null !== $result) {
            return $result;
        }

        if ('\\' === \DIRECTORY_SEPARATOR) {
            return $result = false;
        }

        return $result = (bool) @proc_open('echo 1 >/dev/null', [['pty'], ['pty'], ['pty']], $pipes);
    }
639046
public function validate_target_location() {

        if (!isset($this->assertions['plugintype'])) {
            throw new coding_exception('Required plugin type must be set before calling this');
        }

        $plugintypepath = $this->get_plugintype_location($this->assertions['plugintype']);

        if (is_null($plugintypepath)) {
            $this->add_message(self::ERROR, 'unknowntype', $this->assertions['plugintype']);
            return false;
        }

        if (!is_dir($plugintypepath)) {
            throw new coding_exception('Plugin type location does not exist!');
        }

        // Always check that the plugintype root is writable.
        if (!is_writable($plugintypepath)) {
            $this->add_message(self::ERROR, 'pathwritable', $plugintypepath);
            return false;
        } else {
            $this->add_message(self::INFO, 'pathwritable', $plugintypepath);
        }

        // The target location itself may or may not exist. Even if installing an
        // available update, the code could have been removed by accident (and
        // be reported as missing) etc. So we just make sure that the code
        // can be replaced if it already exists.
        $target = $plugintypepath.'/'.$this->rootdir;
        if (file_exists($target)) {
            if (!is_dir($target)) {
                $this->add_message(self::ERROR, 'targetnotdir', $target);
                return false;
            }
            $this->add_message(self::WARNING, 'targetexists', $target);
            if ($this->get_plugin_manager()->is_directory_removable($target)) {
                $this->add_message(self::INFO, 'pathwritable', $target);
            } else {
                $this->add_message(self::ERROR, 'pathwritable', $target);
                return false;
            }
        }

        return true;
    }
701653
public function validateNamespace()
    {
        $this->ns = ltrim($this->ns, '\\');
        $path = Yii::getAlias('@' . str_replace('\\', '/', $this->ns), false);
        if ($path === false) {
            $this->addError('ns', 'Namespace must be associated with an existing directory.');
        }
    }
917213
private function isHeadValid() : bool
    {
        try {
            $cmd    = new GetCommitHash($this->repo->getRoot());
            $result = $this->runner->run($cmd);
            return $result->isSuccessful();
        } catch (RuntimeException $e) {
            return false;
        }
    }
857385
public function isValidLocalPath()
    {
        //====================================================================//
        // Verify no result in Cache
        if (!isset($this->ValidLocalPath)) {
            $path = Splash::getLocalPath();
            //====================================================================//
            // Verify Local Path Exist
            if (is_null($path) || !is_dir($path)) {
                $this->ValidLocalPath = false;

                return Splash::log()->err(Splash::trans('ErrLocalPath', (string) $path));
            }

            $this->ValidLocalPath = true;
        }

        return $this->ValidLocalPath;
    }
1325743
public function isIndirect()
    {
        $erroringFile = $erroringPackage = null;
        foreach ($this->trace as $line) {
            if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
                continue;
            }
            if (!isset($line['file'])) {
                continue;
            }
            $file = $line['file'];
            if ('-' === $file || 'Standard input code' === $file || !realpath($file)) {
                continue;
            }
            if (!$this->pathOriginatesFromVendor($file)) {
                return false;
            }
            if (null !== $erroringFile && null !== $erroringPackage) {
                $package = $this->getPackage($file);
                if ('composer' !== $package && $package !== $erroringPackage) {
                    return true;
                }
                continue;
            }
            $erroringFile = $file;
            $erroringPackage = $this->getPackage($file);
        }

        return false;
    }
20527
public function accept()
    {
        if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) {
            return false;
        }

        if ($this->excludedPattern) {
            $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
            $path = str_replace('\\', '/', $path);

            return !preg_match($this->excludedPattern, $path);
        }

        return true;
    }
879515
public function isProjectPresent()
    {
        if (isset($this->isProjectPresent)) {
            return $this->isProjectPresent;
        }

        return $this->isProjectPresent = file_exists($this->home->homeDir() . DIRECTORY_SEPARATOR . 'composer.json');
    }
1279246
public function isValidLocalClass()
    {
        $className = SPLASH_CLASS_PREFIX.'\\Local';
        //====================================================================//
        // Verify Results in Cache
        if (isset($this->ValidLocalClass[$className])) {
            return $this->ValidLocalClass[$className];
        }

        $this->ValidLocalClass[$className] = false;

        //====================================================================//
        // Verify Splash Local Core Class Exists
        if (false == class_exists($className)) {
            return Splash::log()->err(Splash::trans('ErrLocalClass', $className));
        }

        //====================================================================//
        // Verify Splash Local Core Extends LocalClassInterface
        try {
            $class = new $className();
            if (!($class instanceof LocalClassInterface)) {
                return Splash::log()->err(Splash::trans('ErrLocalInterface', $className, LocalClassInterface::class));
            }
        } catch (Exception $exc) {
            echo $exc->getMessage();

            return Splash::log()->err($exc->getMessage());
        }

        $this->ValidLocalClass[$className] = true;

        return $this->ValidLocalClass[$className];
    }
1048262
public function isAbsolutePathReference():bool{
		return $this->getScheme() === '' && $this->getAuthority() === '' && isset($this->getPath()[0]) && $this->getPath()[0] === '/';
	}
905360
protected function _validateContent()
    {
        if (!$this->_workingDir) {
            return false;
        }

        $errors = [];
        if (!is_readable("{$this->_workingDir}src") || !is_dir("{$this->_workingDir}src")) {
            $errors[] = __d('installer', 'Invalid package, missing "src" directory.');
        }

        if (!is_readable("{$this->_workingDir}composer.json")) {
            $errors[] = __d('installer', 'Invalid package, missing "composer.json" file.');
        } else {
            $jsonErrors = Plugin::validateJson("{$this->_workingDir}composer.json", true);
            if (!empty($jsonErrors)) {
                $errors[] = __d('installer', 'Invalid "composer.json".');
                $errors = array_merge($errors, (array)$jsonErrors);
            } else {
                $json = (new File("{$this->_workingDir}composer.json"))->read();
                $json = json_decode($json, true);
                list(, $pluginName) = packageSplit($json['name'], true);

                if ($this->params['theme'] && !str_ends_with($pluginName, 'Theme')) {
                    $this->err(__d('installer', 'The given package is not a valid theme.'));

                    return false;
                } elseif (!$this->params['theme'] && str_ends_with($pluginName, 'Theme')) {
                    $this->err(__d('installer', 'The given package is not a valid plugin.'));

                    return false;
                }

                $this->_plugin = [
                    'name' => $pluginName,
                    'packageName' => $json['name'],
                    'type' => str_ends_with($pluginName, 'Theme') ? 'theme' : 'plugin',
                    'composer' => $json,
                ];

                if (Plugin::exists($this->_plugin['name'])) {
                    $exists = plugin($this->_plugin['name']);
                    if ($exists->status) {
                        $errors[] = __d('installer', '{0} "{1}" is already installed.', [($this->_plugin['type'] == 'plugin' ? __d('installer', 'The plugin') : __d('installer', 'The theme')), $this->_plugin['name']]);
                    } else {
                        $errors[] = __d('installer', '{0} "{1}" is already installed but disabled, maybe you want try to enable it?.', [($this->_plugin['type'] == 'plugin' ? __d('installer', 'The plugin') : __d('installer', 'The theme')), $this->_plugin['name']]);
                    }
                }

                if ($this->_plugin['type'] == 'theme' &&
                    !is_readable("{$this->_workingDir}webroot/screenshot.png")
                ) {
                    $errors[] = __d('installer', 'Missing "screenshot.png" file.');
                }

                if (isset($json['require'])) {
                    $checker = new RuleChecker($json['require']);
                    if (!$checker->check()) {
                        $errors[] = __d('installer', '{0} "{1}" depends on other packages, plugins or libraries that were not found: {2}', [($this->_plugin['type'] == 'plugin' ? __d('installer', 'The plugin') : __d('installer', 'The theme')), $this->_plugin['name'], $checker->fail(true)]);
                    }
                }
            }
        }

        if (!file_exists(ROOT . '/plugins') ||
            !is_dir(ROOT . '/plugins') ||
            !is_writable(ROOT . '/plugins')
        ) {
            $errors[] = __d('installer', 'Write permissions required for directory: {0}.', [ROOT . '/plugins/']);
        }

        foreach ($errors as $message) {
            $this->err($message);
        }

        return empty($errors);
    }
615047
public function getHomeDirectory()
    {
        if (!array_key_exists(self::HOME_DIRECTORY, $this->passwd)) {
            throw new \Exception('Could not get user\'s home directory from passwd.');
        }
        return $this->passwd[self::HOME_DIRECTORY];
    }
492198
public function check(): bool
    {
        $path = \app()->storagePath();

        $this->description = Str::replace($this->description, \compact('path'));

        return $this->checkPathIsWritable($path);
    }
739007
public function isDir(): bool
    {
        if ($this->caching == false) {
            return is_dir($this->getAbsoluteFilePath());
        }

        if ($this->isDir == null) {
            $this->isDir = is_dir($this->getAbsoluteFilePath());
        }

        return $this->isDir;
    }