Skip to content

Commit

Permalink
Watch file resources inside containers in debug mode (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
fionera authored and andig committed Dec 3, 2018
1 parent f175ef3 commit a04a3b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Bootstraps/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPPM\Symfony\StrongerNativeSessionStorage;
use PHPPM\Utils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\Resource\FileResource;
use function PHPPM\register_file;

/**
Expand Down Expand Up @@ -87,6 +88,38 @@ public function getApplication()
$app->booted = true;
}, $app);

if ($this->debug) {
Utils::bindAndCall(function () use ($app) {
$container = $app->container;

$containerClassName = substr(strrchr(get_class($app->container), "\\"), 1);
$metaName = $containerClassName . '.php.meta';

Utils::bindAndCall(function () use ($container) {
$container->publicContainerDir = $container->containerDir;
}, $container);

if ($container->publicContainerDir === null) {
return;
}

$metaContent = @file_get_contents($app->container->publicContainerDir . '/../' . $metaName);

// Cannot read the Metadata, returning
if ($metaContent === false) {
return;
}

$containerMetadata = unserialize($metaContent);

foreach ($containerMetadata as $entry) {
if ($entry instanceof FileResource) {
register_file($entry->__toString());
}
}
}, $app);
}

if ($trustedProxies = getenv('TRUSTED_PROXIES')) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
Expand All @@ -97,7 +130,7 @@ public function getApplication()

return $app;
}

/**
* Returns the vendor directory containing autoload.php
*
Expand Down
2 changes: 2 additions & 0 deletions tests/SymfonyMocks/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class Container
{
private $containerDir;

public function has($service)
{
return false;
Expand Down

0 comments on commit a04a3b2

Please sign in to comment.