spaceboy / config-slalom
Make server-dependent configuration slalom easy and readable.
Installs: 15
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/spaceboy/config-slalom
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2025-10-12 07:28:41 UTC
README
Do configuration magic easily in PHP!
Installation:
For PHP 5.3 or higher, use composer:
composer require spaceboy/config-slalom
For lower versions, copy PHP52 directory and require autoload.php file:
<?php
...
require_once('PHP52/autoload.php');
...
Example:
use Spaceboy\ConfigSlalom\Slalom;
$configurator = Slalom::start(new Configurator)
->when()
->serverNameIs('localhost')
->andContinue()
->when()
->serverNameIsIn(['localhost', 'production-server.com'])
->execute(function ($configurator) {
// do something
})
->andContinue()
->when()
->requestUriStarts('/img/')
->execute(function ($configurator) {
$configurator->handleImages();
})
->when()
->requestUriIs('/upload')
->methodIs('POST')
->skip(file_exists('uploaded.file'))
->execute(function ($configurator) {
// do something
})
->otherwise()
->throwException(new \Exception('Wrong server host.'))
->finally()
->execute(
function ($configurator) {
// do something
}
)
->run();
Public methods:
-
start([mixed $configurator]): SlalomFirst directive.
Starts whole "slalom".
-
when([bool $apply = TRUE]): SlalomDirective.
Starts an option.
Use everytime you want to start new option with new set of condition(s).
When
$applyisTRUE(or is not set), new option starts. Otherwise wholewhenclause is ignored.
Actions:
-
throwException(throwable $throwable): SlalomProvides an action.
Throws
$throwable. -
execute(callable $callable[, mixed $args]): SlalomProvides an action.
Executes
$callable(a custom action), possibly with$args. First argument passed to$callableis always$configurator. -
define(string $name, mixed $value): Slalom -
defineNow(string $name, mixed $value): Slalom
Conditions:
-
serverNameIs(string $serverName): SlalomAdds condition.
If current server name (
$_SERVER['SERVER_NAME']) equals$serverName, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
serverNameIsNot(string $serverName): SlalomAdds condition.
If current server name (
$_SERVER['SERVER_NAME']) does not equal$serverName, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
serverNameIsIn(array $serverNameArray): SlalomAdds condition.
If current server name (
$_SERVER['SERVER_NAME']) is in$serverNameArray, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
serverNameNotIn(array $serverNameArray): SlalomAdds condition.
If current server name (
$_SERVER['SERVER_NAME']) is not in$serverNameArray, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
serverNameMatches(string $serverNamePattern): SlalomAdds condition.
If current server name (
$_SERVER['SERVER_NAME']) matches$serverNamePattern, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
serverNameNotMatches(string $serverNamePattern): SlalomAdds condition.
If current server name (
$_SERVER['SERVER_NAME']) does not match$serverNamePattern, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
requestUriIs(string $requestUri): SlalomAdds condition.
If current request URI (
$_SERVER['REQUEST_URI']) is eqal to$requestUri, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
requestUriStarts(string $requestUri): SlalomAdds condition.
If current request URI (
$_SERVER['REQUEST_URI']) starts with$requestUri, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
requestUriContains(string $requestUri): SlalomAdds condition.
If current request URI (
$_SERVER['REQUEST_URI']) contains$requestUri, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
requestUriNotContains(string $requestUri): SlalomAdds condition.
If current request URI (
$_SERVER['REQUEST_URI']) does not contain$requestUri, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
requestMethodIs(string $requestMethod): SlalomAdds condition.
If current request method (
$_SERVER['REQUEST_METHOD']) is eqal to$requestMethod,continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
requestMethodIsNot(string $requestMethod): SlalomAdds condition.
If current request method (
$_SERVER['REQUEST_METHOD']) is not eqal to$requestMethod,continue. Otherwise, continue to next opinion (nextwhen,otherwiseorfinally). -
requestMethodIsIn(array $requestMethodArray): SlalomAdds condition.
If current request method (
$_SERVER['REQUEST_METHOD']) is in$requestMethodArray,continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
requestMethodNotIn(array $requestMethodArray): SlalomAdds condition.
If current request method (
$_SERVER['REQUEST_METHOD']) is not in$requestMethodArray, continue. Otherwise continue to next opinion (nexrwhen,otherwiseorfinally). -
isTrue(callable $callable): SlalomAdds condition.
If result of
$callable) is boolean true, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally).$callableexpects 1 parameter:$configurator. -
portIs(string $port): SlalomAdds condition.
If current port (
$_SERVER['SERVER_PORT']) is equal to$port, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
portIsNot(string $port): SlalomAdds condition.
If current port (
$_SERVER['SERVER_PORT']) is not equal to$port, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
portIsIn(array $portArray): SlalomAdds condition.
If current port (
$_SERVER['SERVER_PORT']) is in$portArray, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
portIsNotIn(array $portArray): SlalomAdds condition.
If current port (
$_SERVER['SERVER_PORT']) is not in$portArray, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
protocolIs(string $protocol): SlalomAdds condition.
If current protocol (
$_SERVER['SERVER_PORT']) is equal to$protocol, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
protocolIsNot(string $protocol): SlalomAdds condition.
If current protocol (
$_SERVER['SERVER_PORT']) is not equal to$protocol, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
protocolIsIn(array $protocolArray): SlalomAdds condition.
If current protocol (
$_SERVER['SERVER_PORT']) is in$protocolArray, continue. If not, continue to next opinion (nextwhen,otherwiseorfinally). -
protocolIsNotIn(array $protocolArray): SlalomAdds condition.
If current protocol (
$_SERVER['SERVER_PORT']) is not in$protocolArray, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
phpVersionIs(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionIsNot(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is not$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionIsIn(integer[] $phpVersions): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is in$phpVersions, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionNotIn(integer[] $phpVersions): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is not in$phpVersions, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionLT(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is less than$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionLE(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is less or equal to$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionEQ(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is equal to$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionNE(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is not equal to$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionGE(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is greater or equal to$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpVersionGT(integer $phpVersion): SlalomAdds condition.
If current version of PHP (
PHP_VERSION_ID) is greater than$phpVersion, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). Argument$phpVersionis integer, inPHP_VERSION_IDconstant format (eg. 50207 for PHP 5.2.7). -
phpSapiIs(string $sapi): SlalomAdds condition.
If current Server API for this build of PHP (
PHP_SAPI) is equal to$sapi, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
phpSapiIsNot(string $sapi): SlalomAdds condition.
If current Server API for this build of PHP (
PHP_SAPI) is not equal to$sapi, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
phpSapiIsIn(string[] $sapi): SlalomAdds condition.
If current Server API for this build of PHP (
PHP_SAPI) is in$sapi, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
phpSapiIsNotIn(string[] $sapi): SlalomAdds condition.
If current Server API for this build of PHP (
PHP_SAPI) is not in$sapi, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileExists(string $fileName): SlalomAdds condition.
If file
$fileNameexists, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileNotExists(string $fileName): SlalomAdds condition.
If file
$fileNamenot exists, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsReadable(string $fileName): SlalomAdds condition.
If file
$fileNameis readable, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsNotReadable(string $fileName): SlalomAdds condition.
If file
$fileNameis not readable, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsFile(string $fileName): SlalomAdds condition.
If file
$fileNameis file, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsNotFile(string $fileName): SlalomAdds condition.
If file
$fileNameis not file, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsDir(string $fileName): SlalomAdds condition.
If file
$fileNameis directory, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsNotDir(string $fileName): SlalomAdds condition.
If file
$fileNameis not directory, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsLink(string $fileName): SlalomAdds condition.
If file
$fileNameis link, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally). -
fileIsNotLink(string $fileName): SlalomAdds condition.
If file
$fileNameis not link, continue. Otherwise continue to next opinion (nextwhen,otherwiseorfinally).
Directives:
-
andContinue(): SlalomDirective.
After execution of directives, continue.
-
onExceptionContinue([bool $continue = TRUE]): SlalomDirective.
When an exception is throwed,
Slalomrun continues.Doesn't overwrite
onException.When set to
TRUE, exception thrown bythrowExceptionis ignored, too. -
onException(callable $callback): SlalomDirective.
When an exception is throwed,
$callbackis executed.When set, automatically sets
onExceptionContinuetoFALSE.$callbackis executed with two parameters:Exception $exception: thrown exceptionmixed $configurator:$configurator
When set, runs also when an exception is thrown by
throwExceptiondirection. -
otherwise(): SlalomDirective.
Defines action which will be exuceted when no other action fits conditions.
-
skip([bool $skip = TRUE]): SlalomDirective.
When
$skipisTRUE(or not set), skip this clause and continue. -
run(): mixedLast directive.
Executes whole "slalom"; without this method, nothing will be done.
Returns
$configuratorpassed instart()method.
Possible conflicts:
For PHP versions before "5.2.7-extra" defines constant PHP_VERSION_ID. So if you define constant PHP_VERSION_ID after ConfigSlalom include, you can experience a conflict.