1. Go to this page and download the library: Download justustheis/registry 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/ */
justustheis / registry example snippets
use Illuminate\Support\Facades\Gate;
public function boot()
{
Gate::define('access-registry', function ($user) {
return $user->isAdmin(); // Customize this logic
});
}
use Illuminate\Support\Facades\Gate;
public function boot()
{
// Define who can access the registry frontend
Gate::define('access-registry', function ($user) {
return $user->isAdmin(); // Adjust this logic as needed
});
}
// config/registry.php
'authorization' => [
'enabled' => true,
'gate' => 'access-registry', // Change this to your preferred gate name
],
use JustusTheis\Registry\Facades\Registry;
// Store a value
Registry::key('app.theme')->value('dark')->set();
// Retrieve a value
$theme = Registry::key('app.theme')->default('light')->get();
// Fluent API
$value = Registry::key('user.preferences')
->default(['notifications' => true])
->encrypt()
->set(['notifications' => false, 'theme' => 'dark']);
use JustusTheis\Registry\Traits\HasRegistry;
class User extends Model
{
use HasRegistry;
}
$user = User::find(1);
// Set user-specific settings
$user->registry()->key('preferences.theme')->value('dark')->set();
// Get user-specific settings
$theme = $user->registry()->key('preferences.theme')->default('light')->get();
// Using helper functions with model scoping
registry_set('notifications.email', true, $user);
$emailNotifications = registry_get('notifications.email', false, $user);
// Access all registry entries for a model
$entries = $user->registryEntries;
// Check if user has specific settings
if ($user->registry()->key('preferences.theme')->exists()) {
// User has custom theme
}
// Encrypt a single value
Registry::key('api.secret')->value('sensitive-data')->encrypt()->set();
// Retrieve encrypted value (automatically decrypted)
$secret = Registry::key('api.secret')->get();
// Using helpers
registry_set('database.password', 'secret123', null, true); // true = encrypt
$password = registry_get('database.password', null, null, true);
// Create hierarchical structure
Registry::key('app.mail.driver')->value('smtp')->set();
Registry::key('app.mail.host')->value('smtp.gmail.com')->set();
Registry::key('app.mail.port')->value(587)->set();
// Work with parent/child relationships
$mailConfig = Registry::key('app.mail.driver');
$parent = $mailConfig->parent(); // Returns 'app.mail' registry
$children = $mailConfig->children(); // Collection of child registries
// Get hierarchical key for display
echo $mailConfig->getHierarchicalKey(); // "app.mail.driver"
// Cache configuration in config/registry.php
'cache' => [
'driver' => 'redis', // or 'memcached', 'file', etc.
'ttl' => 86400, // 24 hours
],
// In config/registry.php
'override' => [
'production' => [
'app.name' => 'app.name', // config('app.name') will check registry first
],
],
// Set override value
Registry::key('app.name')->value('Production App')->set();
// Now config('app.name') returns 'Production App'
echo config('app.name'); // "Production App"
// In config/registry.php
'cascade_on_delete' => true,
'cascade_on_soft_delete' => false,
// Explicit type setting
Registry::key('count')->value(42)->type('integer')->set();
Registry::key('data')->value($array)->type('array')->set();
// Automatic type detection (default)
Registry::key('auto')->value('123')->set(); // Stored as integer 123
Registry::key('auto')->value('true')->set(); // Stored as boolean true
class User extends Model
{
use HasRegistry;
}
// Set user preferences
$user = User::find(1);
$user->registry()->key('preferences')->value([
'theme' => 'dark',
'language' => 'en',
'notifications' => [
'email' => true,
'push' => false,
'sms' => false
]
])->set();
// Get specific preference
$theme = $user->registry()->key('preferences.theme')->default('light')->get();
// Update single preference
$user->registry()->key('preferences.language')->value('es')->set();
// Environment-specific settings
if (app()->environment('production')) {
Registry::key('app.debug')->value(false)->set();
Registry::key('cache.default')->value('redis')->set();
} else {
Registry::key('app.debug')->value(true)->set();
Registry::key('cache.default')->value('file')->set();
}
// API configuration with encryption
Registry::key('services.stripe.secret')
->value('sk_test_...')
->encrypt()
->set();