Skip to content

Instantly share code, notes, and snippets.

@agitso
Created August 26, 2013 18:29
Show Gist options
  • Save agitso/6344818 to your computer and use it in GitHub Desktop.
Save agitso/6344818 to your computer and use it in GitHub Desktop.
Another VO
<?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