Skip to content

Commit

Permalink
Managed to put everything into a more PEAR-like format, adding docblo…
Browse files Browse the repository at this point in the history
…cks where necessary, all *without* replacing my name for Sean's.
  • Loading branch information
robotsnowfall committed Jun 24, 2011
1 parent f1ae1ba commit 058c19f
Show file tree
Hide file tree
Showing 22 changed files with 1,657 additions and 980 deletions.
81 changes: 51 additions & 30 deletions examples/example1/Employee.php
@@ -1,43 +1,64 @@
<?php
/**
* Example Domain Entity
* Example 1
*
* PHP Version 5.3
*
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause
* @link https://github.com/spiralout/Tracks
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/

class Employee extends \Tracks\Model\Entity {
/**
* Example Domain Entity
*
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
class Employee extends \Tracks\Model\Entity
{
public function __construct($guid, $name)
{
$this->guid = $guid;
$this->name = $name;
$this->registerEvents();
}

public function __construct($guid, $name) {
$this->guid = $guid;
$this->name = $name;
$this->registerEvents();
}
public function changeTitle($title)
{
$this->applyEvent(new EventEmployeeChangeTitle($this->getGuid(), $title));
}

public function changeTitle($title) {
$this->applyEvent(new EventEmployeeChangeTitle($this->getGuid(), $title));
}
public function onChangeTitle(EventEmployeeChangeTitle $event)
{
$this->position = new Position($event->title);
}

public function onChangeTitle(EventEmployeeChangeTitle $event) {
$this->position = new Position($event->title);
}

private function registerEvents() {
$this->registerEvent('EventEmployeeChangeTitle', 'onChangeTitle');
}
private function registerEvents()
{
$this->registerEvent('EventEmployeeChangeTitle', 'onChangeTitle');
}

public $name;
public $position;
public $name;
public $position;
}

class EventEmployeeChangeTitle extends \Tracks\Event\Base {

public function __construct($guid, $title) {
parent::__construct($guid);
$this->title = $title;
}
class EventEmployeeChangeTitle extends \Tracks\Event\Base
{
public function __construct($guid, $title)
{
parent::__construct($guid);
$this->title = $title;
}

public $title;
public $title;
}
153 changes: 89 additions & 64 deletions examples/example1/Employer.php
@@ -1,77 +1,102 @@
<?php
/**
* Example Domain Aggregate Root
* Example 1
*
* PHP Version 5.3
*
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause
* @link https://github.com/spiralout/Tracks
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/

class Employer extends \Tracks\Model\AggregateRoot {

public function __construct() {
$this->employees = new \Tracks\Model\EntityList;
$this->registerEvents();
}

public function create($name) {
$guid = \Tracks\Model\Guid::create();
$this->applyEvent(new EventEmployerCreated($guid, $name));
return $guid;
}

public function addNewEmployee($name, $title) {
$employeeGuid = \Tracks\Model\Guid::create();
$this->applyEvent(new EventEmployeeAdded($this->getGuid(), $employeeGuid, $name));
$this->employees->find($employeeGuid)->changeTitle($title);
return $employeeGuid;
}

public function changeEmployeeTitle(\Tracks\Model\Guid $employeeGuid, $title) {
if ($employee = $this->employees->find($employeeGuid)) {
$employee->changeTitle($title);
}
}

protected function onEmployerCreated(EventEmployerCreated $event) {
$this->guid = $event->guid;
$this->name = $event->name;
}

protected function onEmployeeAdded(EventEmployeeAdded $event) {
$this->employees->add(new Employee($event->employeeGuid, $event->name));
}

private function registerEvents() {
$this->registerEvent('EventEmployerCreated', 'onEmployerCreated');
$this->registerEvent('EventEmployeeAdded', 'onEmployeeAdded');
}

public $name;
public $employees;
/**
* Example Domain Aggregate Root
*
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
class Employer extends \Tracks\Model\AggregateRoot
{
public function __construct()
{
$this->employees = new \Tracks\Model\EntityList;
$this->registerEvents();
}

public function create($name)
{
$guid = \Tracks\Model\Guid::create();
$this->applyEvent(new EventEmployerCreated($guid, $name));
return $guid;
}

public function addNewEmployee($name, $title)
{
$employeeGuid = \Tracks\Model\Guid::create();
$this->applyEvent(new EventEmployeeAdded($this->getGuid(), $employeeGuid, $name));
$this->employees->find($employeeGuid)->changeTitle($title);
return $employeeGuid;
}

public function changeEmployeeTitle(\Tracks\Model\Guid $employeeGuid, $title)
{
if ($employee = $this->employees->find($employeeGuid)) {
$employee->changeTitle($title);
}
}

protected function onEmployerCreated(EventEmployerCreated $event)
{
$this->guid = $event->guid;
$this->name = $event->name;
}

protected function onEmployeeAdded(EventEmployeeAdded $event)
{
$this->employees->add(new Employee($event->employeeGuid, $event->name));
}

private function registerEvents()
{
$this->registerEvent('EventEmployerCreated', 'onEmployerCreated');
$this->registerEvent('EventEmployeeAdded', 'onEmployeeAdded');
}

public $name;
public $employees;
}

class EventEmployerCreated extends \Tracks\Event\Base {

public function __construct($guid, $name) {
parent::__construct($guid);
$this->name = $name;
}
class EventEmployerCreated extends \Tracks\Event\Base
{
public function __construct($guid, $name)
{
parent::__construct($guid);
$this->name = $name;
}

public $name;
public $name;
}

class EventEmployeeAdded extends \Tracks\Event\Base {

public function __construct(\Tracks\Model\Guid $guid, $employeeGuid, $name) {
parent::__construct($guid);
$this->employeeGuid = $employeeGuid;
$this->name = $name;
}

public $employeeGuid;
public $name;
class EventEmployeeAdded extends \Tracks\Event\Base
{
public function __construct(\Tracks\Model\Guid $guid, $employeeGuid, $name)
{
parent::__construct($guid);
$this->employeeGuid = $employeeGuid;
$this->name = $name;
}

public $employeeGuid;
public $name;
}


41 changes: 29 additions & 12 deletions examples/example1/Position.php
@@ -1,19 +1,36 @@
<?php
/**
* Example Domain Value Object
* Example 1
*
* PHP Version 5.3
*
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause
* @link https://github.com/spiralout/Tracks
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/

class Position {

public function __construct($title) {
$this->title = $title;
}
/**
* Example Domain Value Object
*
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
class Position
{
public function __construct($title)
{
$this->title = $title;
}

public $title;
public $title;
}

36 changes: 27 additions & 9 deletions examples/example1/Welcomer.php
@@ -1,16 +1,34 @@
<?php
/**
* Example Event Handler
* Example 1
*
* PHP Version 5.3
*
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause
* @link https://github.com/spiralout/Tracks
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/

class Welcomer implements \Tracks\EventHandler\IEventHandler {
/**
* Example Event Handler
*
* @category Tracks
* @package Examples
* @subpackage Example1
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
class Welcomer implements \Tracks\EventHandler\IEventHandler
{

public function execute(\Tracks\Event\Base $event) {
echo "Welcome aboard, {$event->name}!\n";
}
public function execute(\Tracks\Event\Base $event)
{
echo "Welcome aboard, {$event->name}!\n";
}
}

0 comments on commit 058c19f

Please sign in to comment.