<?php namespace sns\filter; \Klass::bind(__NAMESPACE__ . '\\Base', ['overviews' => function () { return ['sns/overview/fixed-header']; }]); trait Base { use \sns\filter\Login; }
<?php namespace sns\filter; \Klass::bind(__NAMESPACE__ . '\\Crud', ['views' => function () { return ['sns/view/crud']; }]); trait Crud { protected abstract function model(); public function index($request) { return $this->crudIndex($request); } public function see($request) { return $this->crudSee($request); } public function add($request) { return $this->crudAdd($request); } public function edit($request) { return $this->crudEdit($request); } public function drop($request) { return $this->crudDrop($request); } public function dropAll($request)
<?php namespace mongo\feature; \Klass::bind(__NAMESPACE__ . '\\Timestamp', ['beforeValidate' => function () { $date = new \DateTime(); $this->created = $this->created ?? $date; $this->updated = $date; }]); trait Timestamp { }
<?php namespace sys\filter; \Klass::bind(__NAMESPACE__ . '\\Db', ['views' => function () { return ['sys/view/db/main']; }, 'overviews' => function () { return ['sns/overview/fixed-drawer']; }]); trait Db { } // function Db__breadcrumbs() { // return function($request) { // //$this->overviews = ['sns/overview/fixed-header']; // $crumbs = [[$url = "/.sys/db/", 'Database']]; // if ($db = $this->request->db) { // $crumbs[] = [$url = "{$url}{$db}/", $db]; // } // if ($coll = $this->request->coll) { // $crumbs[] = [$url = "{$url}{$coll}/", $coll]; // } // return $crumbs; // }; // }
<?php namespace mongo\feature; \Klass::bind(__NAMESPACE__ . '\\SequenceId', ['schema' => function () { return ['_id' => ['type' => 'integer']]; }, 'beforeSave' => function () { if ($this->_id === null) { $this->_id = $this->nextId(); } }]); trait SequenceId { public function nextId() { if (isset($this->_id)) { return; } $command = ['findAndModify' => 'sequence', 'query' => ['_id' => "{$this->collectionName()}._id"], 'update' => ['$inc' => ['seq' => 1]], "upsert" => true, "new" => true]; $cursor = $this->connect()->command($this->dbName(), $command); return current($cursor->toArray())->value->seq; } }
<?php namespace sns\filter; \Klass::bind(__NAMESPACE__ . '\\LoginRequired', ['before' => function ($request) { return $this->requireLogin(); }]); trait LoginRequired { }