Skip to content

Commit

Permalink
Merge pull request #108 from dionsnoeijen/update-events
Browse files Browse the repository at this point in the history
Updating events
  • Loading branch information
dionsnoeijen committed Feb 7, 2020
2 parents b2cf5ce + b4f49be commit da1cf9f
Show file tree
Hide file tree
Showing 22 changed files with 395 additions and 125 deletions.
27 changes: 27 additions & 0 deletions src/SectionField/Event/BeforeCreateAbortedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the SexyField package.
*
* (c) Dion Snoeijen <hallo@dionsnoeijen.nl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types = 1);

namespace Tardigrades\SectionField\Event;

use Throwable;

class BeforeCreateAbortedException extends \Exception
{
public function __construct(
$message = "Aborted before create",
$code = 0,
Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
}
27 changes: 27 additions & 0 deletions src/SectionField/Event/BeforeDeleteAbortedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the SexyField package.
*
* (c) Dion Snoeijen <hallo@dionsnoeijen.nl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types = 1);

namespace Tardigrades\SectionField\Event;

use Throwable;

class BeforeDeleteAbortedException extends \Exception
{
public function __construct(
$message = "Aborted before delete",
$code = 0,
Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
}
27 changes: 27 additions & 0 deletions src/SectionField/Event/BeforeReadAbortedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the SexyField package.
*
* (c) Dion Snoeijen <hallo@dionsnoeijen.nl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types = 1);

namespace Tardigrades\SectionField\Event;

use Throwable;

class BeforeReadAbortedException extends \Exception
{
public function __construct(
$message = "Aborted before read",
$code = 0,
Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
}
27 changes: 27 additions & 0 deletions src/SectionField/Event/BeforeUpdateAbortedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the SexyField package.
*
* (c) Dion Snoeijen <hallo@dionsnoeijen.nl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types = 1);

namespace Tardigrades\SectionField\Event;

use Throwable;

class BeforeUpdateAbortedException extends \Exception
{
public function __construct(
$message = "Aborted before update",
$code = 0,
Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
}
2 changes: 0 additions & 2 deletions src/SectionField/Event/SectionDataRead.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*/
class SectionDataRead extends Event
{
const NAME = 'section.data.read';

/** @var \ArrayIterator */
private $data;

Expand Down
18 changes: 13 additions & 5 deletions src/SectionField/Event/SectionEntryBeforeCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@
*/
class SectionEntryBeforeCreate extends Event
{
const NAME = 'section.entry.before.create';

/** @var CommonSectionInterface */
protected $entry;

/** @var bool */
private $aborted = false;

public function __construct(CommonSectionInterface $entry)
{
$this->entry = $entry;
}

/**
* The entity that is about to be persisted.
*/
public function getEntry(): CommonSectionInterface
{
return $this->entry;
}

public function abort(): void
{
$this->aborted = true;
}

public function aborted(): bool
{
return $this->aborted;
}
}
47 changes: 47 additions & 0 deletions src/SectionField/Event/SectionEntryBeforeDelete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the SexyField package.
*
* (c) Dion Snoeijen <hallo@dionsnoeijen.nl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types = 1);

namespace Tardigrades\SectionField\Event;

use Symfony\Component\EventDispatcher\Event;
use Tardigrades\SectionField\Generator\CommonSectionInterface;

class SectionEntryBeforeDelete extends Event
{
/** @var CommonSectionInterface */
private $entry;

/** @var bool */
private $aborted = false;

public function __construct(
CommonSectionInterface $entry
) {
$this->entry = $entry;
}

public function getEntry(): CommonSectionInterface
{
return $this->entry;
}

public function abort(): void
{
$this->aborted = true;
}

public function aborted(): bool
{
return $this->aborted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,8 @@
use Tardigrades\SectionField\Service\ReadOptionsInterface;
use Tardigrades\SectionField\ValueObject\SectionConfig;

/**
* Class SectionBeforeRead
*
* Before the readers are called this event gives the opportunity to:
* - prefill the data array iterator
* - use / manipulate read options
* - use / manipulate section config
*
* @package Tardigrades\SectionField\Event
*/
class SectionBeforeRead extends Event
class SectionEntryBeforeRead extends Event
{
const NAME = 'section.before.read';

/** @var \ArrayIterator */
private $data;

Expand All @@ -40,6 +28,9 @@ class SectionBeforeRead extends Event
/** @var SectionConfig */
private $sectionConfig;

/** @var bool */
private $aborted = false;

public function __construct(
\ArrayIterator $data,
ReadOptionsInterface $readOptions,
Expand All @@ -50,10 +41,7 @@ public function __construct(
$this->sectionConfig = $sectionConfig;
}

/**
* @return \ArrayIterator
*/
public function getData()
public function getData(): \ArrayIterator
{
return $this->data;
}
Expand All @@ -67,4 +55,14 @@ public function getSectionConfig(): ?SectionConfig
{
return $this->sectionConfig;
}

public function abort(): void
{
$this->aborted = true;
}

public function aborted(): bool
{
return $this->aborted;
}
}
46 changes: 46 additions & 0 deletions src/SectionField/Event/SectionEntryBeforeUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the SexyField package.
*
* (c) Dion Snoeijen <hallo@dionsnoeijen.nl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare (strict_types = 1);

namespace Tardigrades\SectionField\Event;

use Symfony\Component\EventDispatcher\Event;
use Tardigrades\SectionField\Generator\CommonSectionInterface;

class SectionEntryBeforeUpdate extends Event
{
/** @var CommonSectionInterface */
protected $entry;

/** @var bool */
private $aborted = false;

public function __construct(CommonSectionInterface $entry)
{
$this->entry = $entry;
}

public function getEntry(): CommonSectionInterface
{
return $this->entry;
}

public function abort(): void
{
$this->aborted = true;
}

public function aborted(): bool
{
return $this->aborted;
}
}
17 changes: 0 additions & 17 deletions src/SectionField/Event/SectionEntryCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@
use Symfony\Component\EventDispatcher\Event;
use Tardigrades\SectionField\Generator\CommonSectionInterface;

/**
* Class SectionEntryCreated
*
* Dispatched right after all writers have persisted a section entry entity.
*
* @package Tardigrades\SectionField\Event
*/
class SectionEntryCreated extends Event
{
const NAME = 'section.entry.created';

/** @var CommonSectionInterface */
protected $entry;

Expand All @@ -39,19 +30,11 @@ public function __construct(CommonSectionInterface $entry, bool $update)
$this->update = $update;
}

/**
* The Section Entry Entity that was just persisted
*/
public function getEntry(): CommonSectionInterface
{
return $this->entry;
}

/**
* Was it a create or update action?
*
* @return bool
*/
public function getUpdate(): bool
{
return $this->update;
Expand Down
21 changes: 1 addition & 20 deletions src/SectionField/Event/SectionEntryDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@
use Symfony\Component\EventDispatcher\Event;
use Tardigrades\SectionField\Generator\CommonSectionInterface;

/**
* Class SectionEntryDeleted
*
* Right after the section entry entity is deleted from it's data sources, this event is dispatched.
*
* @package Tardigrades\SectionField\Event
*/
class SectionEntryDeleted extends Event
{
const NAME = 'section.entry.deleted';

/** @var CommonSectionInterface */
/** @var CommonSectionInterface */
protected $entry;

/** @var bool */
Expand All @@ -39,21 +30,11 @@ public function __construct(CommonSectionInterface $entry, bool $success)
$this->success = $success;
}

/**
* This entry was deleted.
*
* @return CommonSectionInterface
*/
public function getEntry(): CommonSectionInterface
{
return $this->entry;
}

/**
* Has it been successful?
*
* @return bool
*/
public function getSuccess(): bool
{
return $this->success;
Expand Down

0 comments on commit da1cf9f

Please sign in to comment.