Skip to content

Commit

Permalink
Fix variables leaking from config file scope breaking codegen (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed authored Dec 1, 2017
1 parent b483792 commit 9e05030
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.0.1] - 2017-12-01

### Changed
- Fixed minor issue where variables with certain names defined in the included configuration container's file could impact the code generation scripts
- Fixed issue in generated front controller where config file would be loaded twice

## [3.0.0] - 2017-12-01

### Summary of Breaking Changes
Expand Down
3 changes: 1 addition & 2 deletions bin/generate_front_controller
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ set_exception_handler([$handler, 'handleThrowable']);
$response = (new Dispatcher())
->setContainer(%s)
->setContainer($config)
->setEndpointList('__endpoint_list__.json')
->setParserList('__parser_list__.json')
->setRequest(ServerRequestFactory::fromGlobals())
Expand All @@ -70,7 +70,6 @@ $container = array_key_exists('container', $config)
$fc = sprintf(
$template,
resolveProjectRoot($config['webroot']),
$container,
$container
);

Expand Down
12 changes: 10 additions & 2 deletions bin/load_config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);

use Psr\Container\ContainerInterface;
use SimpleLogger\Stderr;

$root = __DIR__;
Expand Down Expand Up @@ -65,8 +66,15 @@
$stderr->error(".apiconfig[container] must point to a file returning a PSR-11 container");
exit(1);
}
$container = require $config['container'];
if (!$container instanceof Psr\Container\ContainerInterface) {

// Require the container file in a closure to avoid any variable scope
// leaking into the current context.
$load = function (string $path): ContainerInterface {
return require $path;
};
try {
$container = $load($config['container']);
} catch (TypeError $e) {
$stderr->error(".apiconfig[container] must point to a file returning a PSR-11 container");
exit(1);
}
Expand Down

0 comments on commit 9e05030

Please sign in to comment.