PHP code example of hisorange / traits

1. Go to this page and download the library: Download hisorange/traits 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/ */

    

hisorange / traits example snippets


// Check if the key stored in the cache.
$object->runTimeCacheExists('my.last.result.for.X');

// Store a value in the cache by key.
$object->runTimeCacheSet('my.last.result.for.X', [1,2,3]);

// Get the value from the cache by key.
$object->runTimeCacheGet('my.last.result.for.Y', ['Fallback', 'value', 'if not found']);

// Delete a value from the cache.
$object->runTimeCacheDelete('resultX');

// Import a cache array, replace all existing value.
$object->runTimeCacheImport(['r1' => 2, 'r3' => 94]);

// Export the cache array.
$object->runTimeCacheExport();

// Erase the cache values.
$object->runTimeCacheReset();

// Check key in the config.
$object->objectConfigExists('cache_key');

// Set a value in the config.
$object->objectConfigSet('cache_key', 'hoc');

// Get a value from the config.
$object->objectConfigGet('cache_key', 'fallback_value');

// Delete a configuration by key from the object.
$object->objectConfigDelete('cache_key');

// Import a config array.
$object->objectConfigImport($myNewConfig);

// Export the config array.
$object->objectConfigExport();

// Reset the config.
$object->objectConfigReset();

// Import plugins in PLUGIN => CONFIG setup.
$object->pluginCollectionImport([
	'plugins\GoogleSearch' => ['secret_key' => 42],
	'plugins\FacebookSearch' => ['secret_key' => 43],
]);

// Export the collection.
$object->pluginCollectionExport();

// Register a new plugin to the collection.
$object->pluginCollectionRegister('plugins\AOL', ['secret_key' => 42]);

// Deregister a plugin by it's key.
$object->pluginCollectionDeregister('plugins\FacebookSearch');

// Check if a plugin is registered by it's key.
$object->pluginCollectionIsRegistered('plugins\FacebookSearch');


// Practical useage.

$this->pluginCollectionRegister('plugins\Bing', ['secret_key' => 95]);

foreach($this->pluginCollectionExport() as $plugin => $config) {
	
	$pluginInstance = new $plugin;
	$pluginInstance->objectConfigImport($config);

	$plugin->searchOrWhatEver();
}