cs AbstractFactory

This commit is contained in:
Dominik Liebler
2013-09-09 10:39:41 +02:00
parent 8c520c39c3
commit 3b7eb295c8
15 changed files with 39 additions and 52 deletions

View File

@@ -28,6 +28,7 @@ abstract class AbstractFactory
* Creates a text component
*
* @param string $content
*
* @return Text
*/
abstract public function createText($content);
@@ -37,6 +38,7 @@ abstract class AbstractFactory
*
* @param string $path
* @param string $name
*
* @return Picture
*/
abstract public function createPicture($path, $name = '');

View File

@@ -11,7 +11,6 @@ use DesignPatterns\AbstractFactory\Picture as BasePicture;
*/
class Picture extends BasePicture
{
/**
* some crude rendering from HTML output
*
@@ -19,7 +18,6 @@ class Picture extends BasePicture
*/
public function render()
{
return sprintf('<img src="%s" title="$s"/>', $this->_path, $this->_name);
return sprintf('<img src="%s" title="$s"/>', $this->path, $this->name);
}
}

View File

@@ -11,7 +11,6 @@ use DesignPatterns\AbstractFactory\Text as BaseText;
*/
class Text extends BaseText
{
/**
* some crude rendering from HTML output
*
@@ -19,7 +18,6 @@ class Text extends BaseText
*/
public function render()
{
return '<div>' . htmlspecialchars($this->_text) . '</div>';
return '<div>' . htmlspecialchars($this->text) . '</div>';
}
}

View File

@@ -9,12 +9,12 @@ namespace DesignPatterns\AbstractFactory;
*/
class HtmlFactory extends AbstractFactory
{
/**
* Creates a picture component
*
* @param string $path
* @param string $name
*
* @return Html\Picture|Picture
*/
public function createPicture($path, $name = '')
@@ -26,11 +26,11 @@ class HtmlFactory extends AbstractFactory
* Creates a text component
*
* @param string $content
*
* @return Html\Text|Text
*/
public function createText($content)
{
return new Html\Text($content);
}
}

View File

@@ -11,7 +11,6 @@ use DesignPatterns\AbstractFactory\Picture as BasePicture;
*/
class Picture extends BasePicture
{
/**
* some crude rendering from JSON output
*
@@ -19,7 +18,6 @@ class Picture extends BasePicture
*/
public function render()
{
return json_encode(array('title' => $this->_name, 'path' => $this->_path));
return json_encode(array('title' => $this->name, 'path' => $this->path));
}
}

View File

@@ -11,7 +11,6 @@ use DesignPatterns\AbstractFactory\Text as BaseText;
*/
class Text extends BaseText
{
/**
* some crude rendering from JSON output
*
@@ -19,7 +18,6 @@ class Text extends BaseText
*/
public function render()
{
return json_encode(array('content' => $this->_text));
return json_encode(array('content' => $this->text));
}
}

View File

@@ -16,6 +16,7 @@ class JsonFactory extends AbstractFactory
*
* @param string $path
* @param string $name
*
* @return Json\Picture|Picture
*/
public function createPicture($path, $name = '')
@@ -23,16 +24,15 @@ class JsonFactory extends AbstractFactory
return new Json\Picture($path, $name);
}
/**
* Creates a text component
*
* @param string $content
*
* @return Json\Text|Text
*/
public function createText($content)
{
return new Json\Text($content);
}
}

View File

@@ -3,12 +3,12 @@
namespace DesignPatterns\AbstractFactory;
/**
* Interface Media
* Interface MediaInterface
*
* This contract is not part of the pattern, in general case, each component
* are not related
*/
interface Media
interface MediaInterface
{
/**

View File

@@ -5,7 +5,7 @@ namespace DesignPatterns\AbstractFactory;
/**
* Class Picture
*/
abstract class Picture implements Media
abstract class Picture implements MediaInterface
{
/**

View File

@@ -5,7 +5,7 @@ namespace DesignPatterns\AbstractFactory;
/**
* Class Text
*/
abstract class Text implements Media
abstract class Text implements MediaInterface
{
/**
* @var string