master 1
This commit is contained in:
commit
9bbe72a8f3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
vendor/
|
21
composer.json
Normal file
21
composer.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "Glmdev/Meta",
|
||||||
|
"description": "The Framework for Meta enabled Laravel models.",
|
||||||
|
"license": "GNU General Public License v. 3",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Garrett Mills",
|
||||||
|
"email": "garrett@glmills.gq"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"minimum-stability": "beta",
|
||||||
|
"require": {
|
||||||
|
"ramsey/uuid": "^3.2"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\": "app/",
|
||||||
|
"Glmdev\\Meta\\": "packages/Glmdev/Meta/src"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
145
composer.lock
generated
Normal file
145
composer.lock
generated
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"hash": "f28a14cc53da5df0fb6ab22362338395",
|
||||||
|
"content-hash": "b07b9654708a316c5adb2dec5078fe8a",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "paragonie/random_compat",
|
||||||
|
"version": "v2.0.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/paragonie/random_compat.git",
|
||||||
|
"reference": "088c04e2f261c33bed6ca5245491cfca69195ccf"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/088c04e2f261c33bed6ca5245491cfca69195ccf",
|
||||||
|
"reference": "088c04e2f261c33bed6ca5245491cfca69195ccf",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.2.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "4.*|5.*"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"lib/random.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Paragon Initiative Enterprises",
|
||||||
|
"email": "security@paragonie.com",
|
||||||
|
"homepage": "https://paragonie.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
|
||||||
|
"keywords": [
|
||||||
|
"csprng",
|
||||||
|
"pseudorandom",
|
||||||
|
"random"
|
||||||
|
],
|
||||||
|
"time": "2016-04-03 06:00:07"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ramsey/uuid",
|
||||||
|
"version": "3.3.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/ramsey/uuid.git",
|
||||||
|
"reference": "f44f53e5ceb7474a83b6e11e6623ff9d6f6da598"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/ramsey/uuid/zipball/f44f53e5ceb7474a83b6e11e6623ff9d6f6da598",
|
||||||
|
"reference": "f44f53e5ceb7474a83b6e11e6623ff9d6f6da598",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"paragonie/random_compat": "^1.0|^2.0",
|
||||||
|
"php": ">=5.4"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"rhumsaa/uuid": "self.version"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"apigen/apigen": "^4.1",
|
||||||
|
"ircmaxell/random-lib": "^1.1",
|
||||||
|
"jakub-onderka/php-parallel-lint": "^0.9.0",
|
||||||
|
"mockery/mockery": "^0.9.4",
|
||||||
|
"moontoast/math": "^1.1",
|
||||||
|
"phpunit/phpunit": "^4.7|^5.0",
|
||||||
|
"satooshi/php-coveralls": "^0.6.1",
|
||||||
|
"squizlabs/php_codesniffer": "^2.3"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-libsodium": "Provides the PECL libsodium extension for use with the SodiumRandomGenerator",
|
||||||
|
"ext-uuid": "Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator",
|
||||||
|
"ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
|
||||||
|
"moontoast/math": "Provides support for converting UUID to 128-bit integer (in string form).",
|
||||||
|
"ramsey/uuid-console": "A console application for generating UUIDs with ramsey/uuid",
|
||||||
|
"ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Ramsey\\Uuid\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Marijn Huizendveld",
|
||||||
|
"email": "marijn.huizendveld@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Thibaud Fabre",
|
||||||
|
"email": "thibaud@aztech.io"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ben Ramsey",
|
||||||
|
"email": "ben@benramsey.com",
|
||||||
|
"homepage": "https://benramsey.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).",
|
||||||
|
"homepage": "https://github.com/ramsey/uuid",
|
||||||
|
"keywords": [
|
||||||
|
"guid",
|
||||||
|
"identifier",
|
||||||
|
"uuid"
|
||||||
|
],
|
||||||
|
"time": "2016-03-22 18:40:53"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "beta",
|
||||||
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": [],
|
||||||
|
"platform-dev": []
|
||||||
|
}
|
68
src/Meta.php
Normal file
68
src/Meta.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: garrett
|
||||||
|
* Date: 4/17/16
|
||||||
|
* Time: 11:59 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Glmdev\Meta;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
|
||||||
|
class Meta extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $fillable = ['meta', 'uuid'];
|
||||||
|
|
||||||
|
function read( $key ){
|
||||||
|
$meta = unserialize( $this->meta );
|
||||||
|
return $meta[ $key ];
|
||||||
|
}
|
||||||
|
|
||||||
|
function write( $key, $value ){
|
||||||
|
$meta = unserialize( $this->meta );
|
||||||
|
$meta[ $key ] = $value;
|
||||||
|
$meta = serialize( $meta );
|
||||||
|
$this->meta = $meta;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
function readRaw(){
|
||||||
|
return $this->meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeRaw( $serialized ){
|
||||||
|
$this->meta = $serialized;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUUID(){
|
||||||
|
return $this->uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUuid(){
|
||||||
|
// check if UUID is set
|
||||||
|
if( !isset($this->uuid) || is_null($this->uuid) || $this->uuid === "" ){
|
||||||
|
$this->uuid = Uuid::uuid4();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rawUuid( Uuid $uuid ){
|
||||||
|
$this->uuid = $uuid;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function formTable( Blueprint $table ){
|
||||||
|
$table->uuid('uuid');
|
||||||
|
$table->text('meta');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user