Skip to content

Instantly share code, notes, and snippets.

@cr0wst
Created February 23, 2018 16:49
Show Gist options
  • Save cr0wst/c6d13c3e17359e5c7e8e40eee008da15 to your computer and use it in GitHub Desktop.
Save cr0wst/c6d13c3e17359e5c7e8e40eee008da15 to your computer and use it in GitHub Desktop.
Inner Builder Example
<?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