commit()
который отвечает за вычисление изменений в сохранённых в UoW объектах и синхронизацию этих изменений с хранилищем (базой данных).commit()
паттерна Unit of Work для вычисления разницы между исходными данными и накопленными изменениями. class Tweet
{
private $id;
private $content;
public function __construct(int $id, string $content)
{
$this->id = $id;
$this->content = $content;
}
public function getId(): int
{
return $this->id;
}
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content): void
{
$this->content = $content;
}
}
CREATE TABLE tweets (
id INTEGER PRIMARY KEY,
content VARCHAR(255) NOT NULL
)
class UnitOfWork
{
private $connection;
private $identityMap;
private $data;
public function __construct(\PDO $connection)
{
$this->connection = $connection;
$this->identityMap = [];
$this->data = [];
}
public function find(int $id): Tweet
{
if (isset($this->identityMap[$id])) {
return $this->identityMap[$id];
}
$query = $this->connection->prepare('SELECT * FROM tweets WHERE id = ?');
$query->execute([ $id ]);
if (false === $data = $query->fetch()) {
throw new \Exception(\sprintf('Tweet with id "%d" not found.', $id));
}
$id = (int) $data['id'];
// Исходные данные сохраняются для того, чтобы в дальнейшем вычислить изменения.
$this->data[$id] = $data;
$tweet = new Tweet($id, $data['content']);
$this->identityMap[$id] = $tweet;
return $tweet;
}
public function commit(): void
{
// Вообще говоря, лучше вычислить все изиенения, создать один "большой" запрос
// и выполнить его внутри транзакции, но для простоты мы сделаем для каждого
// изменения отдельный запрос
$query = $this->connection->prepare('UPDATE tweets SET content = ? WHERE id = ?');
foreach ($this->identityMap as $tweet) {
if ($tweet->getContent() !== $this->data[$tweet->getId()]['content']) {
$query->execute([ $tweet->getContent(), $tweet->getId() ]);
}
}
}
}
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
use RefreshDatabase;
$task = factory(\App\Task::class)->create([
'archive' => false
]);
$response = $this->get('/current_tasks');
$response->assertStatus(200)
->assertJson([$task->toArray()]);
/*!
* Main styles
*
* @author delphinpro <delphinpro@gmail.com>
* @copyright copyright © 2018 delphinpro
* @license licensed under the MIT license
*/
//==
//== Config & mixins
//== ======================================= ==//
$DEV_MODE: true;
@import "vrhythm.cfg.scss";
@import "grid.cfg.scss";
@import "../../node_modules/bs-grid-system/source/scss/bs-grid";
@import "../../node_modules/vrhythm/source/mixins/rhythm";
@import "main.cfg.scss";
@import "mixins.scss";
@import "../../node_modules/tiny-slider/src/tiny-slider";
//==
//== Global styles
//== ======================================= ==//
@import "webfonts.scss";
@import "vendor/normalize";
@import "base/global.scss";
@import "base/grid-system.scss";
@import "base/page.scss";
@import "base/site.scss";
@import "base/table.scss";
@import "base/input.scss";
@import "base/uploadbox.scss";
@import "base/buttons.scss";
@import "base/checkbox.scss";
@import "base/radio.scss";
@import "base/radio-button.scss";
@import "base/radio-panel.scss";
@import "base/controls-group.scss";
@import "base/form-field.scss";
@import "base/auto-height.scss";
@import "base/transitions.scss";
//==
//== Blocks
//== ======================================= ==//
@import "blocks/availability.scss";
@import "blocks/availability-details.scss";
@import "blocks/back-link.scss";
@import "blocks/benefit-block.scss";
@import "blocks/block-heading.scss";
@import "blocks/breadcrumb.scss";
@import "blocks/btn-close.scss";
@import "blocks/callback-link.scss";
@import "blocks/checked-list.scss";
@import "blocks/ci.scss";
@import "blocks/clear-link.scss";
@import "blocks/document-list.scss";
@import "blocks/download-link.scss";
@import "blocks/email-link.scss";
@import "blocks/entry-item.scss";
@import "blocks/expert-consult.scss";
@import "blocks/goods-attributes.scss";
@import "blocks/heading.scss";
@import "blocks/icons.scss";
@import "blocks/info-text.scss";
@import "blocks/logo.scss";
@import "blocks/paginate.scss";
@import "blocks/phone-link.scss";
@import "blocks/phone-with-icon.scss";
@import "blocks/phone.scss";
@import "blocks/popular-links.scss";
@import "blocks/price.scss";
@import "blocks/print-link.scss";
@import "blocks/section.scss";
@import "blocks/service-description.scss";
@import "blocks/services.scss";
@import "blocks/share-block.scss";
@import "blocks/show-all.scss";
@import "blocks/smenu-box.scss";
@import "blocks/smenu.scss";
@import "blocks/tags.scss";
@import "blocks/unordered-list.scss";
@import "blocks/worktime.scss";
@import "blocks/zoom.scss";
//==
//== Blocks
//== ======================================= ==//
@import "blocks/about-us-section.scss";
@import "blocks/article-section.scss";
@import "blocks/benefits.scss";
@import "blocks/carousel.scss";
@import "blocks/cart.scss";
@import "blocks/delivery-map.scss";
@import "blocks/delivery-partners.scss";
@import "blocks/delivery.scss";
@import "blocks/footer.scss";
@import "blocks/header.scss";
@import "blocks/help-me.scss";
@import "blocks/load-more.scss";
@import "blocks/nav-catalog.scss";
@import "blocks/nav.scss";
@import "blocks/navbar.scss";
@import "blocks/news-section.scss";
@import "blocks/panel.scss";
@import "blocks/params-panel.scss";
@import "blocks/payment-block.scss";
@import "blocks/search.scss";
@import "blocks/catalog-table.scss";
@import "blocks/catalog-grid.scss";
@import "blocks/time-range.scss";
//==
//== Components
//== ======================================= ==//
@import "components/spin.scss";
@import "components/selector.scss";
@import "components/tabs.scss";
@import "components/hamburger.scss";
@import "components/fixed-bar.scss";
@import "components/step-indicator.scss";
@import "components/complete-screen.scss";
@import "components/ordering.scss";
@import "components/order-complete.scss";
@import "components/summary.scss";
@import "components/goods.scss";
@import "components/basket-contains.scss";
@import "components/basket-goods.scss";
@import "components/basket.scss";
@import "components/icon-complete.scss";
@import "components/big-order-form.scss";
@import "components/feedback-form.scss";
@import "components/modal.scss";
@import "components/vue-scrollbar.scss";
@import "components/mobile-menu.scss";
@import "components/gallery.scss";
//==
//== Page specific classes
//== ======================================= ==//
@import "pages/home.scss";
@import "pages/articles.scss";
@import "pages/catalog.scss";
@import "pages/product.scss";
@import "pages/terms.scss";
@import "pages/services.scss";
@import "pages/news.scss";
@import "pages/feedback.scss";
@import "pages/page404.scss";
//==
//== Helpers & other classes
//== ======================================= ==//
@import "base/helpers.scss";
@import "base/printer.scss";
$user = new User('Paul')
$comments = $user->getCommentsOfLastPost()
function getCommentsOfLastPost()
{
$posts = new Posts()
$posts->getCommentsOfLastPostUser($this)
}
дом->лестница->машина_Opel->магазин->кассир_Люба->купить_молоко();
дом->лестница->машина_BMW->магазин->кассир_Люба->купить_молоко();
дом->лестница->велосипед->магазин->кассир_Люба->купить_молоко();
дом->лестница->велосипед->магазин->кассир_Клава->купить_молоко();
дом->лифт->велосипед->магазин->кассир_Клава->купить_молоко();
магазин->купить_молоко();