mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-05 06:27:25 +02:00
cs AbstractFactory
This commit is contained in:
@@ -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 = '');
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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>';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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
|
||||
{
|
||||
|
||||
/**
|
@@ -5,7 +5,7 @@ namespace DesignPatterns\AbstractFactory;
|
||||
/**
|
||||
* Class Picture
|
||||
*/
|
||||
abstract class Picture implements Media
|
||||
abstract class Picture implements MediaInterface
|
||||
{
|
||||
|
||||
/**
|
||||
|
@@ -5,7 +5,7 @@ namespace DesignPatterns\AbstractFactory;
|
||||
/**
|
||||
* Class Text
|
||||
*/
|
||||
abstract class Text implements Media
|
||||
abstract class Text implements MediaInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
|
Reference in New Issue
Block a user