PHP code example of motomedialab / runtime-store

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

    

motomedialab / runtime-store example snippets


// creating a group and setting your first value...
store()->group('groupName')->set('key', 'value')

// getting a key from a group
store()->group('groupName')->get('key')

// checking if a group exists
store()->hasGroup('groupName')

// deleting a group
store()->deleteGroup('groupName')
  
// in Laravel, there are multiple ways to resolve a global instance of the store...  
app(\Motomedialab\RuntimeStore\RuntimeStore::class)->get('value');
\Motomedialab\RuntimeStore\RuntimeStoreFacade::get('value');
app('store')->get('value');  
resolve('store')->get('value');  

// there is a global store() helper method, demonstrated below.
// this also integrates with Laravel's application layer directly (when installed).
store()->get('value');

class YourClass {
  use \Motomedialab\RuntimeStore\Traits\HasRuntimeStore;

  public function yourMethod()
  {
    return $this->store()->remember('key', function () {
      return 'This value will be remembered as long as the request is active!';
    });
  }
}

// procedual example
$store = null;  
function store() {  
    global $store;  
    
    if ($store) {
      return $store;
    }
    
    return $store = new \Motomedialab\RuntimeStore\RuntimeStore;  
}

// OOP example
class ClassWithStore {
  protected $store;

  public function store() {
    if ($this->store) {
      return $this->store;
    }
    
    return $this->store = new \MotoMediaLab\RuntimeStore\RuntimeStore;
  }
}