Created
August 26, 2013 18:29
-
-
Save agitso/6344818 to your computer and use it in GitHub Desktop.
Another VO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Famly\Core\Value; | |
use Doctrine\ORM\Mapping as ORM; | |
use TYPO3\Flow\Annotations as Flow; | |
/** | |
* @Flow\ValueObject | |
*/ | |
class Color { | |
const RED = 'RED'; | |
const GREEN = 'GREEN'; | |
const BLUE = 'BLUE'; | |
const YELLOW = 'YELLOW'; | |
const PURPLE = 'PURPLE'; | |
const ORANGE = 'ORANGE'; | |
/** | |
* @var string | |
* @ORM\Id | |
*/ | |
protected $persistenceId; | |
/** | |
* @var string | |
* @Flow\Validate(type="NotEmpty") | |
*/ | |
protected $color; | |
/** | |
* @param string $color | |
* @throws \InvalidArgumentException | |
*/ | |
public function __construct($color) { | |
$this->persistenceId = \TYPO3\Flow\Utility\Algorithms::generateUUID(); | |
$this->color = $color; | |
if(!in_array($this->color, array( | |
self::RED, | |
self::GREEN, | |
self::BLUE, | |
self::YELLOW, | |
self::PURPLE, | |
self::ORANGE | |
))) { | |
throw new \InvalidArgumentException('Color is not valid. Must one of the defined colors.'); | |
} | |
} | |
/** | |
* @return string | |
*/ | |
public function __toString() { | |
return $this->color; | |
} | |
/** | |
* @return string | |
*/ | |
public function getColor() { | |
return $this->color; | |
} | |
/** | |
* @param Color $color | |
* @return bool | |
*/ | |
public function equals($color) { | |
return $this->color === $color->color; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment