Skip to content

Commit 9e05030

Browse files
authored
Fix variables leaking from config file scope breaking codegen (#15)
1 parent b483792 commit 9e05030

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [3.0.1] - 2017-12-01
8+
9+
### Changed
10+
- Fixed minor issue where variables with certain names defined in the included configuration container's file could impact the code generation scripts
11+
- Fixed issue in generated front controller where config file would be loaded twice
12+
713
## [3.0.0] - 2017-12-01
814

915
### Summary of Breaking Changes

bin/generate_front_controller

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ set_exception_handler([$handler, 'handleThrowable']);
4949
5050
5151
$response = (new Dispatcher())
52-
->setContainer(%s)
52+
->setContainer($config)
5353
->setEndpointList('__endpoint_list__.json')
5454
->setParserList('__parser_list__.json')
5555
->setRequest(ServerRequestFactory::fromGlobals())
@@ -70,7 +70,6 @@ $container = array_key_exists('container', $config)
7070
$fc = sprintf(
7171
$template,
7272
resolveProjectRoot($config['webroot']),
73-
$container,
7473
$container
7574
);
7675

bin/load_config.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4+
use Psr\Container\ContainerInterface;
45
use SimpleLogger\Stderr;
56

67
$root = __DIR__;
@@ -65,8 +66,15 @@
6566
$stderr->error(".apiconfig[container] must point to a file returning a PSR-11 container");
6667
exit(1);
6768
}
68-
$container = require $config['container'];
69-
if (!$container instanceof Psr\Container\ContainerInterface) {
69+
70+
// Require the container file in a closure to avoid any variable scope
71+
// leaking into the current context.
72+
$load = function (string $path): ContainerInterface {
73+
return require $path;
74+
};
75+
try {
76+
$container = $load($config['container']);
77+
} catch (TypeError $e) {
7078
$stderr->error(".apiconfig[container] must point to a file returning a PSR-11 container");
7179
exit(1);
7280
}

0 commit comments

Comments
 (0)