Created
February 23, 2018 16:49
-
-
Save cr0wst/c6d13c3e17359e5c7e8e40eee008da15 to your computer and use it in GitHub Desktop.
Inner Builder Example
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 Smcrow\Sample; | |
class Sample | |
{ | |
protected $id; | |
protected $comments; | |
public static function builder() | |
{ | |
return new class extends Sample { | |
public function id($id) | |
{ | |
$this->id = $id; | |
return $this; | |
} | |
public function comments($staff) | |
{ | |
$this->staff = $staff; | |
return $this; | |
} | |
public function build() | |
{ | |
$sample = new parent; | |
$sample->id = $this->id; | |
$sample->comments = $this->comments; | |
return $sample; | |
} | |
}; | |
} | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getComments() | |
{ | |
return $this->comments; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment