Skip to content

Instantly share code, notes, and snippets.

@cn007b
Last active August 20, 2018 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cn007b/2c345fa725e43e7722f4d7fa324ca4a2 to your computer and use it in GitHub Desktop.
Save cn007b/2c345fa725e43e7722f4d7fa324ca4a2 to your computer and use it in GitHub Desktop.
Value Object instead of Form - ValueObject static
<?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