/**
  * Main Find Helper function that concludes a search, returning results
  *
  * @return array|RedBean_OODBBean
  */
 public function find($force_make = false, $force_array = false)
 {
     if (empty($this->related)) {
         $ft = 'find' . ucfirst($this->find);
         if ($this->params) {
             $r = $this->r->{$ft}($this->type, $this->makeQuery(), $this->params);
         } else {
             $r = $this->r->{$ft}($this->type);
         }
         if (!empty($this->preload)) {
             $this->r->preload($r, $this->preload);
         }
         if (!is_array($r) && !empty($r)) {
             $r = array($r);
         }
     } else {
         if ($this->find == 'all') {
             $this->find = '';
         }
         $rt = 'related' . ucfirst($this->find);
         if ($this->params) {
             $r = $this->r->{$rt}($this->related[0], $this->type, $this->makeQuery(), $this->params);
         } else {
             $r = $this->r->{$rt}($this->related[0], $this->type);
         }
         if (!is_array($r) && !empty($r)) {
             $r = array($r);
         }
         if (count($r) && count($this->related) > 1) {
             foreach ($r as $k => $b) {
                 if ($k === 0) {
                     continue;
                 }
                 foreach ($this->related as $bean) {
                     if (!$this->r->areRelated($b, $bean)) {
                         unset($r[$k]);
                     }
                 }
             }
         }
     }
     if ($force_make && empty($r)) {
         $r = array($this->r->_($this->type, $this->params_plain, true));
         if (!empty($this->related)) {
             $this->r->associate($r[0], $this->related);
         }
     }
     $this->free();
     if (count($r) > 1 || $force_array) {
         return $r;
     } elseif (is_array($r)) {
         return array_pop($r);
     } else {
         return null;
     }
 }
Esempio n. 2
0
 public static function emit($update)
 {
     $resource_exact = self::$r->x->resource->path($update->path)->find();
     $resource_type = self::$r->x->resource->path($update->type)->find();
     if (empty($resource_exact->id) && empty($resource_type->id)) {
         return;
     }
     $subscribers = array();
     if (!empty($resource_exact->id)) {
         $subscribers = array_unique(array_merge($subscribers, $resource_exact->sharedSubscriber));
     }
     if (!empty($resource_type->id)) {
         $subscribers = array_unique(array_merge($subscribers, $resource_type->sharedSubscriber));
     }
     if (empty($subscribers)) {
         return;
     }
     foreach ($subscribers as $subscriber) {
         // Don't update the subscriber making the call
         if (!empty(self::$subscriber)) {
             if ($subscriber->name == self::$subscriber) {
                 continue;
             }
         }
         if (empty($subscriber->callback)) {
             // No callback, so this will be stashed for retrieval by the subscriber
             self::$r->associate($subscriber, $update);
         } else {
             // TODO: Support internal callbacks
             /*
              * Most likely, this would be one or more callback observers
              * that are submitted when the Pipeline is set up. Then, we
              * could allow stuff like:
              *
              * RedBean_Pipeline::addCallbackObserver( 'my', new myObserver() );
              *
              * RedBean_Pipeline::addSubscriber(
              *    'test_subscriber',
              *    'my.customMethod'
              * );
              *
              * When the update is emitted, myObserver::customMethod(); is
              * called with the update as only input.
              */
         }
     }
 }
Esempio n. 3
0
 public static function isPermitted($subject, $resource, $action)
 {
     $resource = self::getResource($resource);
     $restriction = self::getRestriction($resource);
     self::$r->associate($subject, $restriction);
 }