Runs the directory parsing process.

@param string $path optional path
556144
private function _runParse( $path = NULL )
    {
        $startLevels  = $this->_getRealLevel( $this->_rootPath );
        $endLevels    = $startLevels + $this->levels;
        $currentLevel = 0;

        if ( NULL !== $path )
        {
            $this->_dirs[ ] = $path;
        }

        do
        {
            $dir          = array_shift( $this->_dirs );
            $currentLevel = $this->_getRealLevel( $dir );

            if ( $currentLevel < $endLevels )
            {
                $this->_parse( $dir );
            }
        } while ( count( $this->_dirs ) > 0 );
    }
1237446
public static function parse($path) {
        if (!file_exists($path)) {
            throw new \Exception("$path not found");
        }

        $src = file_get_contents($path);
        if (!$src) {
            throw new \Exception("could not read $path");
        }

        // first of all do we have any frontmatter in there?
        preg_match(self::$frontmatter_regex, $src, $matches);
        if (!empty($matches)) {
            // if we have an empty frontmatter, this will fail 
            // but we still want to act like there was something there
            if (!($frontmatter = json_decode(trim($matches[1]), true))) {
                $frontmatter = array();
            }
        } else {
            $frontmatter = false;
        }

        // remove any frontmatter
        $plain_src = preg_replace(self::$frontmatter_regex, "", $src);

        return array(
            'frontmatter' => $frontmatter,
            'content' => $plain_src
        );
    }
327047
private function performFindAndReplaceInFile(
        string $path
    ): void {
        $this->findAndReplaceHelper->findReplace(
            'use ' . RelationsGenerator::FIND_ENTITIES_NAMESPACE . '\\' . RelationsGenerator::FIND_ENTITY_NAME,
            "use {$this->entityFqn}",
            $path
        );
        $this->findAndReplaceHelper->findReplace(
            'use ' .
            RelationsGenerator::FIND_ENTITY_INTERFACE_NAMESPACE .
            '\\' .
            RelationsGenerator::FIND_ENTITY_INTERFACE_NAME,
            "use {$this->entityInterfaceFqn}",
            $path
        );
        $this->findAndReplaceHelper->findReplaceRegex(
            '%use(.+?)Relations\\\TemplateEntity(.+?);%',
            'use ${1}Relations\\' . $this->singularNamespace . '${2};',
            $path
        );
        $this->findAndReplaceHelper->findReplaceRegex(
            '%use(.+?)Relations\\\TemplateEntity(.+?);%',
            'use ${1}Relations\\' . $this->pluralNamespace . '${2};',
            $path
        );
        $this->findAndReplaceHelper->findReplaceRegex(
            '%(Has|Reciprocates)(Required|)TemplateEntity%',
            '${1}${2}' . $this->singularNamespacedName,
            $path
        );
        $this->findAndReplaceHelper->findReplaceRegex(
            '%(Has|Reciprocates)(Required|)TemplateEntities%',
            '${1}${2}' . $this->pluralNamespacedName,
            $path
        );
        $this->findAndReplaceHelper->findReplace(
            RelationsGenerator::FIND_ENTITY_INTERFACE_NAME,
            $this->namespaceHelper->basename($this->entityInterfaceFqn),
            $path
        );
        $this->findAndReplaceHelper->replaceName($this->singularNamespacedName, $path);
        $this->findAndReplaceHelper->replacePluralName($this->pluralNamespacedName, $path);
        $this->findAndReplaceHelper->replaceProjectNamespace($this->projectRootNamespace, $path);
    }
623474
protected function setSourcePath($path)
    {
        if ($this->sourcePath === self::DUMMY_PATH) {
            $this->sourcePath = $path;
        } elseif ($this->sourcePath === self::EMPTY_PATH) {
            $this->sourcePath = null;
        }
    }
235743
public function setDictionaryPath(string $path): void
    {
        $this->customDictPath = $path;
        $this->supportedLanguages = null; // Clear cache because $path can contain new languages
    }
1336871
public function compile( $path = null )
	{
		if ( $path )
			$this->setPath( $path );

		if ( !is_null( $this->cachePath ) )
		{
			$contents = $this->compileString( $this->files->get( $this->getPath() ) );
			$this->files->put( $this->getCompiledPath( $this->getPath() ), $contents );
		}
	}
538981
public function parse($path)
    {
        // Require the file, if it throws an exception, rethrow it
        try {
            $temp = require $path;
        } catch (Exception $exception) {
            throw new ParseException(
                array(
                    'message'   => 'PHP file threw an exception',
                    'exception' => $exception,
                )
            );
        }

        // If we have a callable, run it and expect an array back
        if (is_callable($temp)) {
            $temp = call_user_func($temp);
        }

        // Check for array, if its anything else, throw an exception
        if (!is_array($temp)) {
            throw new UnsupportedFormatException('PHP file does not return an array');
        }

        return $temp;
    }
1215023
public function setPath(string $path = ''): void
    {
        $this->path = '/';
        if ($path != '') {
            $this->path .= \substr($path, 0, 1) === '/' ? \substr($path, 1) : $path;
        }
    }
1130368
public function processAlias($path = null)
    {
        if (!isset($path)) {
            $path = $this->path;
        }

        if ($this->db->isInitialized() && $this->config->get('alias', true)) {
            foreach (array_keys($this->findAlias($path)) as $pattern) {
                $this->callAliasController($pattern, $path, null);
            }
        }
    }
268048
public function load($path)
    {
        $tests = $this->getTests($path);
        foreach ($tests as $test) {
            $this->context->setFile($test);
            include $test;
        }
    }
835048
public function load($path)
    {
        list($data, $items) = array(array(), array($path));

        if (substr((string) $path, -4) !== '.php')
        {
            $directory = new \RecursiveDirectoryIterator($path);

            $iterator = new \RecursiveIteratorIterator($directory);

            $regex = new \RegexIterator($iterator, '/^.+\.php$/i', 1);

            $items = (array) array_keys(iterator_to_array($regex));
        }

        foreach ((array) $items as $item)
        {
            $name = $this->rename($item, $path);

            $data = require $item;

            $this->set((string) $name, $data);
        }
    }
841684
protected function makeDirectory($path)
    {
        if (! $this->getFiles()->isDirectory(dirname($path))) {
            
            $this->getFiles()->makeDirectory(dirname($path), 0777, true, true);
        }
    }
658664
protected function runCommand($command, $path)
    {
        $process = (new Process($command, $path))->setTimeout(null);

        if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
            $process->setTty(true);
        }

        $process->run(function ($type, $line) {
            $this->output->write($line);
        });
    }
309483
public function onFileChanged($path)
    {
        if (!Daemon::lintFile($path)) {
            Daemon::log(__METHOD__ . ': Detected parse error in ' . $path);
            return;
        }
        foreach ($this->files[$path] as $cb) {
            if (is_callable($cb) || is_array($cb)) {
                $cb($path);
            } elseif (!Daemon::$process->IPCManager->importFile($cb, $path)) {
                $this->rmWatch($path, $cb);
            }
        }
    }
889033
private function _parse( $dir )
    {
        foreach ( scandir( $dir ) as $file )
        {
            if ( '.' === $file || '..' === $file )
            {
                continue;
            }

            if ( is_dir( $dir . DS . $file ) )
            {
                $this->_dirs[ ] = $dir . DS . $file;

                $this->dirHandles[ ] = $dir . DS . $file;
            }
            elseif ( 'file' === filetype( $dir . DS . $file ) )
            {
                $this->fileHandles[ ] = $dir . DS . $file;
            }
            elseif ( 'link' === filetype( $dir . DS . $file ) )
            {
                $this->linkHandles[ ] = $dir . DS . $file;
            }
        }
    }
47121
public static function load(string $path): void
    {
        $filePath = \absolute_path($path, static::FILE);
        if (!\is_readable($filePath) || !\is_file($filePath)) {
            return;
        }

        $array = self::optimizeGet($path, $filePath);

        if ($array === false) {
            $array = \parse_ini_file($filePath, false, INI_SCANNER_RAW);
        }

        foreach ($array as $name => $value) {
            static::set($name, $value);
        }

        self::optimizeSet($path, $array, $filePath);
    }
1041844
public function setPath($path)
    {
        if (!file_exists($path))
        {
            mkdir($path, 0777, true);
        }

        $this->path = $path;
    }