public function processCommand() { $this->watch = $this->getRoute()->getMatchedParam('watch', false); $this->fileSystem = new Filesystem(); $this->setUpServer(); $command = sprintf('php -S %s:%d -t %s %s', 'localhost', '8000', $this->getPath() . '/' . $this->getPHPoole()->getOption('output.dir'), sprintf('%s/.phpoole/router.php', $this->getPath())); $this->wlAnnonce(sprintf('Starting server (http://%s:%d)...', 'localhost', '8000')); $process = new Process($command); if (!$process->isStarted()) { // write changes cache if ($this->watch) { $finder = new Finder(); $finder->files()->name('*.md')->name('*.html')->in([$this->getPath() . '/' . $this->getPHPoole()->getOption('content.dir'), $this->getPath() . '/' . $this->getPHPoole()->getOption('layouts.dir')]); if (is_dir($this->getPath() . '/' . $this->getPHPoole()->getOption('themes.dir'))) { $finder->in($this->getPath() . '/' . $this->getPHPoole()->getOption('themes.dir')); } $resourceCache = new ResourceCacheMemory(); $resourceWatcher = new ResourceWatcher($resourceCache); $resourceWatcher->setFinder($finder); $this->fileSystem->dumpFile($this->getPath() . '/.phpoole/watch.flag', ''); } // start server try { $process->start(); Plateform::openBrowser('http://localhost:8000'); while ($process->isRunning()) { // watch changes? if ($this->watch) { $resourceWatcher->findChanges(); if ($resourceWatcher->hasChanges()) { $this->fileSystem->dumpFile($this->getPath() . '/.phpoole/changes.flag', ''); // re-generate $this->wlAlert('Changes detected!'); $callable = new Build(); call_user_func($callable, $this->getRoute(), $this->getConsole()); } } usleep(1000000); // 1 s } } catch (ProcessFailedException $e) { $this->tearDownServer(); echo $e->getMessage(); exit(2); } } }