コード例 #1
0
ファイル: Cursor.php プロジェクト: maslosoft/mangan
 /**
  * Return the current element
  * @return Document|null
  * @since v1.3.4
  */
 public function current()
 {
     $document = $this->_cursor->current();
     if (empty($document)) {
         return null;
     }
     return RawArray::toModel($document, $this->_model);
 }
コード例 #2
0
 public function testIfWillPopulateSimplePlainModel()
 {
     $data = ['_class' => PlainWithBasicAttributes::class, 'int' => 12345, 'string' => 'foo', 'bool' => false, 'float' => 110.23, 'array' => ['new', 'array'], 'null' => null];
     $model = RawArray::toModel($data);
     $this->assertTrue($model instanceof PlainWithBasicAttributes);
     unset($data['_class']);
     foreach ($data as $field => $value) {
         $this->assertSame($value, $model->{$field});
     }
 }
コード例 #3
0
ファイル: EntityManager.php プロジェクト: maslosoft/mangan
 /**
  * Reloads document from database.
  * It return true if document is reloaded and false if it's no longer exists.
  *
  * @return boolean
  */
 public function refresh()
 {
     $conditions = PkManager::prepareFromModel($this->model)->getConditions();
     $data = $this->getCollection()->findOne($conditions);
     if (null !== $data) {
         RawArray::toModel($data, $this->model, $this->model);
         return true;
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: Finder.php プロジェクト: maslosoft/mangan
 /**
  * Creates an model with the given attributes.
  * This method is internally used by the find methods.
  * @param mixed[] $data attribute values (column name=>column value)
  * @return AnnotatedInterface|null the newly created document. The class of the object is the same as the model class.
  * Null is returned if the input data is false.
  * @since v1.0
  */
 protected function populateRecord($data)
 {
     if ($data !== null) {
         if (!empty($data['$err'])) {
             throw new ManganException(sprintf("There is an error in query: %s", $data['$err']));
         }
         $model = RawArray::toModel($data, $this->model);
         ScenarioManager::setScenario($model, ScenariosInterface::Update);
         Event::trigger($model, FinderInterface::EventAfterFind);
         return $model;
     } else {
         return null;
     }
 }