2017 © Pedro Peláez
 

library traits

Useful PHP traits.

image

hisorange/traits

Useful PHP traits.

  • Thursday, May 1, 2014
  • by hisorange
  • Repository
  • 1 Watchers
  • 1 Stars
  • 358,918 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

HiSoRange - PHP Traits v1.0.0


Collection of some useful traits what I use across my packages but can be useful to any1 (who knows right?)., (*1)

RunTimeCache trait


Simple runtime cache for results or objects. The traits reserves the $runTimeCache variable., (*2)

// 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();

ObjetConfig trait


Store configuration on an object. The trait reserves the $objectConfig variable., (*3)

// 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();

PluginCollection trait


Register and deregister plugins to an object. The trait reserves the $pluginCollection variable., (*4)

// 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();
}

The Versions

01/05 2014

dev-master

9999999-dev

Useful PHP traits.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Varga Zsolt (hisorange)

php traits

01/05 2014

1.0.0

1.0.0.0

Useful PHP traits.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Varga Zsolt (hisorange)

php traits