コード例 #1
0
ファイル: Database.php プロジェクト: simon-downes/spf
 /**
  * Inject a profiler object.
  *
  * @param   \spf\util\Profiler   $profiler
  * @return  self
  */
 public function setProfiler($profiler)
 {
     if ($profiler instanceof \spf\util\Profiler) {
         $this->profiler = $profiler;
     } else {
         throw new \InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . ' expects \\spf\\util\\Profiler, ' . \spf\var_info($profiler) . 'given');
     }
     return $this;
 }
コード例 #2
0
ファイル: Immutable.php プロジェクト: simon-downes/spf
 public function __construct($data)
 {
     $this->_data = array();
     if ($data) {
         if (!(is_array($data) || $data instanceof Traversable)) {
             throw new Exception('Not traversable: ' . \spf\var_info($data));
         }
         foreach ($data as $k => $v) {
             $this->_data[$k] = $v;
         }
     }
 }
コード例 #3
0
ファイル: Object.php プロジェクト: simon-downes/spf
 /**
  * Set multiple values.
  *
  * @return self
  */
 public function set($data)
 {
     if ($data instanceof Object) {
         $data = $data->toArray();
     } elseif (!(is_array($data) || $data instanceof Traversable)) {
         throw new Exception('Not traversable: ' . \spf\var_info($data));
     }
     foreach ($data as $k => $v) {
         $this->__set($k, $v);
     }
     return $this;
 }
コード例 #4
0
ファイル: EntityAttachment.php プロジェクト: simon-downes/spf
 /**
  * Implementations should call this function to ensure we're only dealing with items of the class we care about.
  *
  * @param $items array|Entity   the entity or array of entities to attach related items to
  * @return array
  */
 protected function filterItems($items)
 {
     $entity_class = $this->entity_class;
     if ($items instanceof $this->entity_class) {
         $items = array($items->id => $items);
     } elseif (!is_array($items)) {
         throw new \InvalidArgumentException(sprintf("\\%s::%s() expects %s or array(), '%s' given", get_class($this), __FUNCTION__, $this->entity_class, \spf\var_info($items)));
     }
     // make sure we're only dealing with instances of ContentItem
     return array_filter($items, function ($item) use($entity_class) {
         return $item instanceof $entity_class;
     });
 }
コード例 #5
0
 /**
  * Register an EntityAttachment instance with the repository.
  * If the $name parameter is an array is is assumed to be an array of (name => attachment instances).
  * @param  string|array   $name   name by which the attachment can be referenced
  * @param  \spf\model\EntityAttachment   $attachment
  * @return self
  */
 public function registerAttachment($name, $attachment = null)
 {
     if (is_array($name)) {
         foreach ($name as $k => $v) {
             $this->registerAttachment($k, $v);
         }
     } elseif (!$attachment instanceof EntityAttachment) {
         throw new \InvalidArgumentException(sprintf("\\%s expects \\spf\\models\\EntityAttachment, '%s' given", __METHOD__, \spf\var_info($attachment)));
     } else {
         $this->attachments[$name] = $attachment;
     }
     return $this;
 }