2017 © Pedro Peláez
 

library diskstore

image

tequilarapido/diskstore

  • Friday, April 6, 2018
  • by nbourguig
  • Repository
  • 2 Watchers
  • 0 Stars
  • 272 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 66 % Grown

The README.md

tequilrapido/diskstore

This packages help with storing data to disk. This comes handy if persisting data in a database is not the best solution. (ie, Data size etc ...), (*1)

Storing entities to disks., (*2)

Install

composer require "tequilarapido/diskstore:^1.0.0"

Usage

  • define a disk where entities will be stored in config/filesystem.php

'disks' => [ // ... 'tweets' => ['driver' => 'local', 'root' => storage_path('/documents/locations')], // ... ],
  • define your entity extending StorableObject. Every public property will be serialized and saved.

class FollowerLocation extends StorableObject { public $twitter_id; public $location; /** This identifies the entity. And must be unique */ public static function keyName() { return 'twitter_id'; } /** Defines the disk that wil be used for storage **/ public static function diskName() { return 'locations'; } public function setLocation($location) { $this->location = $location; return $this; } // ... }
  • Check if an entity is persisted to disk :

if(FollowerLocation::exists($twitter_id)) { //... }
  • Save entity :

FollowerLocation::fromArray([ 'twitter_id' => $follower->twitter_id, 'location' => $location, ])->store();
  • Work with an empty entity with a specific uid :

FollowerLocation::for($twitter_id)->setLocation($location)->store();
  • Find an entity by its unique id
    FollowerLocation::find($follower->twitter_id);
  • Find an entity by its unique id or create/store on if none
    FollowerLocation::findOrNew($twitter_id)->setLocation($location)->store();
  • Customize what will be serialized by overriding the toArray method

class FollowerLocation extends StorableObject { // ... public function toArray() { return [ 'twitter_id' => '@requried! (uid)', // ... ]; } }
  • Get stored entity full path file :

```php $path = FollowerLocation::path(), (*3)

``, (*4)

The Versions