Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AbstractEmbeddedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public function __get($name)
{
if ($this->checkName($name)) {
return $this->storage;
} else {
return parent::__get($name);
}

return parent::__get($name);
}

public function __set($name, $value)
Expand Down
8 changes: 8 additions & 0 deletions EmbeddedDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class EmbeddedDocument extends Model
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function formName()
{
if (!empty($this->_formName)) {
Expand All @@ -45,6 +46,7 @@ public function formName()
/**
* @param $formName
*/
#[\ReturnTypeWillChange]
public function setFormName($formName)
{
if (!empty($formName)) {
Expand All @@ -56,6 +58,7 @@ public function setFormName($formName)
* set link to primary model
* @param ActiveRecord $model
*/
#[\ReturnTypeWillChange]
public function setPrimaryModel(ActiveRecord $model)
{
$this->_primaryModel = $model;
Expand All @@ -66,6 +69,7 @@ public function setPrimaryModel(ActiveRecord $model)
* @return ActiveRecord
* @throws UnknownPropertyException
*/
#[\ReturnTypeWillChange]
public function getPrimaryModel()
{
if (!isset($this->_primaryModel)) {
Expand All @@ -79,6 +83,7 @@ public function getPrimaryModel()
* set link to primary model attribute
* @param $value
*/
#[\ReturnTypeWillChange]
public function setSource($value)
{
$this->_source = $value;
Expand All @@ -88,6 +93,7 @@ public function setSource($value)
* Save embedded model as attribute on primary model
* @throws UnknownPropertyException
*/
#[\ReturnTypeWillChange]
public function save()
{
if (!isset($this->_source) || !$this->primaryModel->hasAttribute($this->_source)) {
Expand All @@ -96,6 +102,7 @@ public function save()
$this->primaryModel->save(false, [$this->_source]);
}

#[\ReturnTypeWillChange]
public function setScenario($scenario)
{
if (array_key_exists($scenario, $this->scenarios())) {
Expand All @@ -111,6 +118,7 @@ public function setScenario($scenario)
* Пустым считается объект все атрибуты которого пусты (empty($value)) или равны значениям по-умолчанию. Не учитывает параметры "when" и "isEmpty" валидаторов "по-умолчанию".
* @return bool
*/
#[\ReturnTypeWillChange]
public function isEmpty()
{
$notEmptyAttributes = [];
Expand Down
8 changes: 6 additions & 2 deletions EmbedsManyBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ class EmbedsManyBehavior extends AbstractEmbeddedBehavior
{
public $initEmptyScenarios = [];

#[\ReturnTypeWillChange]
public function getFormName($index)
{
if ($this->setFormName) {
return Html::getInputName($this->owner, $this->fakeAttribute."[{$index}]");
} else {
return null;
}

return null;
}

/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
protected function setAttributes($attributes, $safeOnly = true)
{
$this->storage->removeAll();
Expand All @@ -51,6 +53,7 @@ protected function setAttributes($attributes, $safeOnly = true)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
protected function getAttributes()
{
return $this->storage->attributes;
Expand All @@ -59,6 +62,7 @@ protected function getAttributes()
/**
* @return Storage
*/
#[\ReturnTypeWillChange]
public function getStorage()
{
if (empty($this->_storage)) {
Expand Down
7 changes: 5 additions & 2 deletions EmbedsOneBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
class EmbedsOneBehavior extends AbstractEmbeddedBehavior
{
#[\ReturnTypeWillChange]
protected function setAttributes($attributes, $safeOnly = true)
{
$this->storage->scenario = $this->owner->scenario;
Expand All @@ -20,18 +21,20 @@ protected function setAttributes($attributes, $safeOnly = true)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
protected function getAttributes()
{
if ($this->saveEmpty || !$this->storage->isEmpty()) {
return $this->storage->attributes;
} else {
return null;
}

return null;
}

/**
* @return EmbeddedDocument
*/
#[\ReturnTypeWillChange]
public function getStorage()
{
if (empty($this->_storage)) {
Expand Down
20 changes: 20 additions & 0 deletions Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Storage extends Component implements StorageInterface, \Countable, \Iterat

private $_cursor = 0;

#[\ReturnTypeWillChange]
public function removeAll()
{
$this->_container = [];
Expand All @@ -27,6 +28,7 @@ public function removeAll()
* @param string $name
* @param Event $event
*/
#[\ReturnTypeWillChange]
public function trigger($name, Event $event = null)
{
parent::trigger($name, $event);
Expand All @@ -39,6 +41,7 @@ public function trigger($name, Event $event = null)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function validate()
{
$hasError = false;
Expand All @@ -54,6 +57,7 @@ public function validate()
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function getAttributes()
{
$attributes = [];
Expand All @@ -69,6 +73,7 @@ public function getAttributes()
* @param $condition
* @return null| EmbeddedDocument
*/
#[\ReturnTypeWillChange]
public function get($condition)
{
list($attribute, $value) = $condition;
Expand All @@ -87,6 +92,7 @@ public function get($condition)
* @param $object
* @return bool
*/
#[\ReturnTypeWillChange]
public function set($condition, $object)
{
list($attribute, $value) = $condition;
Expand All @@ -100,6 +106,7 @@ public function set($condition, $object)
return false;
}

#[\ReturnTypeWillChange]
public function sort($field)
{
$attributes = $this->attributes;
Expand All @@ -111,6 +118,7 @@ public function sort($field)
});
}

#[\ReturnTypeWillChange]
public function offsetSet($offset, $model)
{
if (is_null($offset)) {
Expand All @@ -120,6 +128,7 @@ public function offsetSet($offset, $model)
$this->_container[$offset] = $model;
}

#[\ReturnTypeWillChange]
public function current()
{
if ($this->valid($this->_cursor)) {
Expand All @@ -129,47 +138,56 @@ public function current()
}
}

#[\ReturnTypeWillChange]
public function key()
{
return $this->_cursor;
}

#[\ReturnTypeWillChange]
public function next()
{
++$this->_cursor;
}

#[\ReturnTypeWillChange]
public function rewind()
{
$this->_cursor = 0;
}

#[\ReturnTypeWillChange]
public function valid()
{
return $this->offsetExists($this->_cursor);
}

#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->_container[$offset]);
}

#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->_container[$offset]);
$this->_container = array_values($this->_container);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return isset($this->_container[$offset]) ? $this->_container[$offset] : null;
}

#[\ReturnTypeWillChange]
public function count()
{
return count($this->_container);
}

#[\ReturnTypeWillChange]
public function getNextIndex()
{
$count = count($this->_container);
Expand All @@ -181,6 +199,7 @@ public function getNextIndex()
* @param string $scenario
* @return void
*/
#[\ReturnTypeWillChange]
public function setScenario($scenario)
{
foreach ($this->_container as $model) {
Expand All @@ -189,6 +208,7 @@ public function setScenario($scenario)
}
}

#[\ReturnTypeWillChange]
public function __toString()
{
return '';
Expand Down
2 changes: 1 addition & 1 deletion StorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface StorageInterface extends \ArrayAccess
/**
* Triggers an event
* @param string $name the event name
* @param Event $event the event parameter. If not set, a default [[Event]] object will be created.
* @param Event|null $event the event parameter. If not set, a default [[Event]] object will be created.
*/
public function trigger($name, Event $event = null);

Expand Down
17 changes: 16 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
"yiisoft/yii2-codeception": "*",
"codeception/codeception": "*"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer" : true
},
"process-timeout": 1800,
"fxp-asset": {
"enabled": false
}
},
"autoload": {
"psr-4": {
"consultnn\\embedded\\": "."
Expand All @@ -30,5 +39,11 @@
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}