Files
admin-php-module/core/app/Models/Subscriber.php
2021-01-14 15:00:07 +03:00

31 lines
1007 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Subscriber extends Model
{
protected $table = 'subscribers';
public static function add($event, $callback, $weight = 0)
{
list($destination_module, $destination_method) = explode(':', $callback);
list($source_module, $source_method) = explode(':', $event);
$code = strtolower($destination_module . '_' . $destination_method . '_after_' . $source_module . '_' . $source_method);
if (Subscriber::where('code', $code)->count() == 0) {
$subscriber = new Subscriber([
'code' => $code,
'destination_module' => strtolower($destination_module),
'destination_method' => strtolower($destination_method),
'source_module' => strtolower($source_module),
'source_method' => strtolower($source_method),
'weight' => $weight
]);
$subscriber->save();
}
}
}