Skip to content

Commit

Permalink
FIX Add quotes to constants in YAML to ensure syntax validity
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Feb 27, 2017
1 parent deca009 commit 458ea65
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion _config/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SilverStripe\Core\Injector\Injector:
SilverStripe\Core\Cache\CacheFactory:
class: 'SilverStripe\Core\Cache\DefaultCacheFactory'
constructor:
directory: `TEMP_FOLDER`
directory: '`TEMP_FOLDER`'
Psr\SimpleCache\CacheInterface.GDBackend_Manipulations:
factory: SilverStripe\Core\Cache\CacheFactory
constructor:
Expand Down
2 changes: 1 addition & 1 deletion _config/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SilverStripe\Core\Injector\Injector:
constructor:
0: 'en'
1: null
2: `TEMP_FOLDER`
2: '`TEMP_FOLDER`'
properties:
ConfigCacheFactory: %$Symfony\Component\Config\ConfigCacheFactoryInterface
calls:
Expand Down
16 changes: 8 additions & 8 deletions docs/en/02_Developer_Guides/05_Extending/05_Injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ As well as properties, method calls can also be specified:

## Using constants as variables

Any of the core constants can be used as a service argument by quoting with back ticks "`".
Any of the core constants can be used as a service argument by quoting with back ticks "`". Please ensure you also quote the entire value (see below).


:::yaml
CachingService:
class: SilverStripe\Cache\CacheProvider
properties:
CacheDir: `TEMP_DIR`
```yaml
CachingService:
class: SilverStripe\Cache\CacheProvider
properties:
CacheDir: '`TEMP_DIR`'
```

Note: undefined variables will be replaced with null
Note: undefined variables will be replaced with null.
## Factories
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Injector/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ public function convertServiceProperty($value)
return $this->get($id);
}

// Evaluate constants surrounded by back ticks
if (preg_match('/^`(?<name>[^`]+)`$/', $value, $matches)) {
// Evaluate constants surrounded by back ticks (and quotes)
if (preg_match('/^[\'"]?`(?<name>[^`]+)`[\'"]?$/', $value, $matches)) {
$value = defined($matches['name']) ? constant($matches['name']) : null;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Core/Injector/InjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function testConstantUsage()
'properties' => array(
'filters' => array(
'`BASE_PATH`',
'`TEMP_FOLDER`',
'"`TEMP_FOLDER`"',
'`NOT_DEFINED`',
'THIRDPARTY_DIR' // Not back-tick escaped
)
Expand Down

0 comments on commit 458ea65

Please sign in to comment.