1. Go to this page and download the library: Download monospice/spicy-identifiers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
monospice / spicy-identifiers example snippets
// Call a dynamic method:
$someClass->callSomeDynamicMethod('some argument');
// The dynamic method call is handled by the __call() magic method of a class.
// $methodCalled is the name of the dynamic method: "callSomeDynamicMethod"
public function __call($methodCalled, array $arguments)
{
// Use Spicy Identifiers to work with the dynamic method
$method = DynamicMethod::parse($methodCalled);
// Check if the method name starts and ends with certain strings
if ($method->startsWith('call') && $method->endsWith('Method')) {
$method->replace(0, 'get')->replace(3, 'Variable');
// The dynamic method name is now "getSomeDynamicVariable"
}
// Alert the developer if they called a method that doesn't exist
$method->throwExceptionIfMissingOn($this);
// Check that the method
$config = [
'config_directive_1' => 'some value',
'config_directive_2' => 'some value',
...
];
class UsesConfig
{
public function __construct(array $config)
{
foreach ($config as $option => $value) {
DynamicMethod::parse($option)
->prepend('set')
->throwExceptionIfMissingOn($this, 'Invalid option: ' . $option)
->callOn($this, [ $value ]); // calls setConfigDirectiveN()
}
}
public function setConfigDirective1($value) { ... }
public function setConfigDirective2($value) { ... }
...
}
use Monospice\SpicyIdentifiers\DynamicVariable;
use Monospice\SpicyIdentifiers\DynamicMethod;
use Monospice\SpicyIdentifiers\DynamicFunction;
use Monospice\SpicyIdentifiers\DynamicClass;
use Monospice\SpicyIdentifiers\Tools\CaseFormat;
// parse and output with the default case format (camel case)
$identifier = DynamicIdentifier::parse('identifierName');
// parse with an explicit case format, output with the default format
$identifier = DynamicIdentifier::parseFromUnderscore('identifier_name');
// parse with an explicit format, and set an explicit output format
$identifier = DynamicIdentifier::parseFromUnderscore('identifier_name')
->setOutputFormat(CaseFormat::UPPER_CAMEL_CASE);