Last active
August 20, 2018 13:59
-
-
Save cn007b/2c345fa725e43e7722f4d7fa324ca4a2 to your computer and use it in GitHub Desktop.
Value Object instead of Form - ValueObject static
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 | |
class ValueObject | |
{ | |
protected $name; | |
private function __construct() | |
{} | |
public static function fromArray(array $args) | |
{ | |
if (!isset($args['name']) || $args['name'] === '') { | |
throw new InvalidArgumentException('name cannot be blank'); | |
} | |
$instance = new self(); | |
$instance->name = $args['name']; | |
return $instance; | |
} | |
public function getName() | |
{ | |
return $this->name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment