mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9106 from webbuilders-group/config-ext-loaded
NEW: Added support for config condition if PHP extension is loaded
This commit is contained in:
commit
717646feb0
@ -339,6 +339,7 @@ You then list any of the following rules as sub-keys, with informational values
|
||||
- 'envvarset', in which case the value(s) should be environment variables that must be set
|
||||
- 'constantdefined', in which case the value(s) should be constants that must be defined
|
||||
- 'envorconstant' A variable which should be defined either via environment vars or constants
|
||||
- 'extensionloaded', in which case the PHP extension(s) must be loaded
|
||||
|
||||
For instance, to add a property to "foo" when a module exists, and "bar" otherwise, you could do this:
|
||||
|
||||
|
@ -182,6 +182,9 @@ class CoreConfigFactory
|
||||
})
|
||||
->addRule('moduleexists', function ($module) {
|
||||
return ModuleLoader::inst()->getManifest()->moduleExists($module);
|
||||
})
|
||||
->addRule('extensionloaded', function ($extension) {
|
||||
return extension_loaded($extension);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -225,4 +225,21 @@ class ConfigManifestTest extends SapphireTest
|
||||
'Fragment is included if both blocks succeed.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testExtensionLoaded()
|
||||
{
|
||||
$config = $this->getConfigFixtureValue('ExtensionLoaded');
|
||||
|
||||
$this->assertEquals(
|
||||
'Yes',
|
||||
@$config['SessionExtLoaded'],
|
||||
'Only rule correctly detects loaded PHP extension'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'No',
|
||||
@$config['DummyExtLoaded'],
|
||||
'Except rule correctly detects not-loaded PHP extension'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
---
|
||||
Only:
|
||||
extensionloaded: "session"
|
||||
---
|
||||
SilverStripe\Core\Tests\Manifest\ConfigManifestTest:
|
||||
ExtensionLoaded:
|
||||
SessionExtLoaded: Yes
|
||||
---
|
||||
Only:
|
||||
extensionloaded: "silverstripe_ext"
|
||||
---
|
||||
SilverStripe\Core\Tests\Manifest\ConfigManifestTest:
|
||||
ExtensionLoaded:
|
||||
DummyExtLoaded: Yes
|
||||
---
|
||||
Except:
|
||||
extensionloaded: "session"
|
||||
---
|
||||
SilverStripe\Core\Tests\Manifest\ConfigManifestTest:
|
||||
ExtensionLoaded:
|
||||
SessionExtLoaded: No
|
||||
---
|
||||
Except:
|
||||
extensionloaded: "silverstripe_ext"
|
||||
---
|
||||
SilverStripe\Core\Tests\Manifest\ConfigManifestTest:
|
||||
ExtensionLoaded:
|
||||
DummyExtLoaded: No
|
Loading…
Reference in New Issue
Block a user