Skip to content

Instantly share code, notes, and snippets.

@mnapoli
Created November 14, 2013 18:21
Show Gist options
  • Save mnapoli/7471722 to your computer and use it in GitHub Desktop.
Save mnapoli/7471722 to your computer and use it in GitHub Desktop.
Factory methods
<?php
class Image
{
private $width;
private $height;
private $content;
public static function createEmpty($width, $height, $bgcolor = null)
{
$image = new Image();
$image->width = $width;
$image->height = $height;
$image->content = …;
return $image;
}
public static function createFromFile($file)
{
$reader = new FileReader($file);
return self::createFromString($file->getContent());
}
public static function createFromString($str)
{
$image = new Image();
$image->width = $width;
$image->height = $height;
$image->content = …;
return $image;
}
private function __construct()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment