Example #1
0
 private static function configureDB($cfg)
 {
     self::$r->selectDatabase($cfg->name);
     if (!empty($cfg->prefix)) {
         self::$r->prefix($cfg->prefix);
     }
     self::$r->redbean->beanhelper->setModelFormatter('Saltwater\\RedBean\\Provider\\Db::entity');
     self::$r->useWriterCache(true);
 }
 public function log($level, $message, $context = null)
 {
     if (!is_null($this->db)) {
         $log = $this->db->dispense('log');
     } else {
         $log = R::dispense('log');
     }
     $log->level = $level;
     $log->message = $message;
     $log = $this->addContext($log, $context);
     if (!is_null($this->db)) {
         $this->db->store($log);
     } else {
         R::store($log);
     }
 }
 /**
  * Pretty much the same as find(), just for counting beans
  *
  * @return int
  */
 public function count()
 {
     if (empty($this->related)) {
         $r = $this->r->count($this->type, $this->makeQuery(), $this->params);
     } else {
         $r = 0;
         foreach ($this->related as $bean) {
             $r += $this->r->relatedCount($bean, $this->type, $this->makeQuery(), $this->params);
         }
     }
     $this->free();
     return $r;
 }
 /**
  * Execute a REST DELETE Request
  *
  * @param string $path RESTFul path to resource
  *
  * @return int ID of the stored object
  */
 public function handleRESTDeleteRequest($path)
 {
     if (!is_string($path)) {
         return null;
     }
     $path = explode('/', $path);
     if (count($path) < 2) {
         return null;
     }
     try {
         $bean = $this->instance->load($path[0], $path[1]);
         $this->instance->trash($bean);
         return $path[1];
     } catch (Exception $exception) {
         return null;
     }
 }
Example #5
0
 public static function isPermitted($subject, $resource, $action)
 {
     $resource = self::getResource($resource);
     $restriction = self::getRestriction($resource);
     self::$r->associate($subject, $restriction);
 }
 private static function makeUpdate($bean, $path, $type, $operation)
 {
     $json = json_encode($bean->export());
     return self::$r->_('update', array('operation' => $operation, 'path' => $path, 'type' => $type, 'objectid' => $bean->id, 'object' => $json, 'created' => self::$r->isoDateTime(), 'hash' => sha1($json)), true);
 }