@@ -26,75 +26,75 @@ |
||
| 26 | 26 | class Factory |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Configuration Settings. |
|
| 31 | - * |
|
| 32 | - * @since 1.0.0 |
|
| 33 | - * |
|
| 34 | - * @var ConfigInterface |
|
| 35 | - */ |
|
| 36 | - protected $config; |
|
| 29 | + /** |
|
| 30 | + * Configuration Settings. |
|
| 31 | + * |
|
| 32 | + * @since 1.0.0 |
|
| 33 | + * |
|
| 34 | + * @var ConfigInterface |
|
| 35 | + */ |
|
| 36 | + protected $config; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Type of element the factory wants to create. |
|
| 40 | - * |
|
| 41 | - * @since 1.0.0 |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $element; |
|
| 38 | + /** |
|
| 39 | + * Type of element the factory wants to create. |
|
| 40 | + * |
|
| 41 | + * @since 1.0.0 |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $element; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Instantiate a Factory object. |
|
| 49 | - * |
|
| 50 | - * @since 1.0.0 |
|
| 51 | - * |
|
| 52 | - * @param ConfigInterface $config Configuration settings. |
|
| 53 | - * @param string $element The type of element to instantiate a factory for. |
|
| 54 | - * |
|
| 55 | - * @throws FailedToInstantiateFactoryException When an unknown element type is requested. |
|
| 56 | - */ |
|
| 57 | - public function __construct(ConfigInterface $config, $element) |
|
| 58 | - { |
|
| 47 | + /** |
|
| 48 | + * Instantiate a Factory object. |
|
| 49 | + * |
|
| 50 | + * @since 1.0.0 |
|
| 51 | + * |
|
| 52 | + * @param ConfigInterface $config Configuration settings. |
|
| 53 | + * @param string $element The type of element to instantiate a factory for. |
|
| 54 | + * |
|
| 55 | + * @throws FailedToInstantiateFactoryException When an unknown element type is requested. |
|
| 56 | + */ |
|
| 57 | + public function __construct(ConfigInterface $config, $element) |
|
| 58 | + { |
|
| 59 | 59 | |
| 60 | - $this->config = $config; |
|
| 60 | + $this->config = $config; |
|
| 61 | 61 | |
| 62 | - if (! $this->config->hasKey($element)) { |
|
| 63 | - throw new FailedToInstantiateFactoryException(sprintf( |
|
| 64 | - 'Could not instantiate Factory for unknown Element Type "%1$s".', |
|
| 65 | - $element |
|
| 66 | - )); |
|
| 67 | - } |
|
| 62 | + if (! $this->config->hasKey($element)) { |
|
| 63 | + throw new FailedToInstantiateFactoryException(sprintf( |
|
| 64 | + 'Could not instantiate Factory for unknown Element Type "%1$s".', |
|
| 65 | + $element |
|
| 66 | + )); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $this->element = $element; |
|
| 70 | - } |
|
| 69 | + $this->element = $element; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Create and return a new instance of an element. |
|
| 74 | - * |
|
| 75 | - * @since 1.0.0 |
|
| 76 | - * |
|
| 77 | - * @param string $type Type of element to create. |
|
| 78 | - * @param mixed $arguments Optional. Arguments to pass to the object. |
|
| 79 | - * |
|
| 80 | - * @return object New instance of the requested class. |
|
| 81 | - * @throws FailedToInstantiateClassException If an unknown element type is requested. |
|
| 82 | - */ |
|
| 83 | - public function create($type, $arguments = null) |
|
| 84 | - { |
|
| 72 | + /** |
|
| 73 | + * Create and return a new instance of an element. |
|
| 74 | + * |
|
| 75 | + * @since 1.0.0 |
|
| 76 | + * |
|
| 77 | + * @param string $type Type of element to create. |
|
| 78 | + * @param mixed $arguments Optional. Arguments to pass to the object. |
|
| 79 | + * |
|
| 80 | + * @return object New instance of the requested class. |
|
| 81 | + * @throws FailedToInstantiateClassException If an unknown element type is requested. |
|
| 82 | + */ |
|
| 83 | + public function create($type, $arguments = null) |
|
| 84 | + { |
|
| 85 | 85 | |
| 86 | - $classMap = $this->config[$this->element]; |
|
| 86 | + $classMap = $this->config[$this->element]; |
|
| 87 | 87 | |
| 88 | - if (! array_key_exists($type, $classMap)) { |
|
| 89 | - throw new FailedToInstantiateClassException(sprintf( |
|
| 90 | - 'Could not create object, unknown Type "%1$s" for "%2$s" elements.', |
|
| 91 | - $type, |
|
| 92 | - $this->element |
|
| 93 | - )); |
|
| 94 | - } |
|
| 88 | + if (! array_key_exists($type, $classMap)) { |
|
| 89 | + throw new FailedToInstantiateClassException(sprintf( |
|
| 90 | + 'Could not create object, unknown Type "%1$s" for "%2$s" elements.', |
|
| 91 | + $type, |
|
| 92 | + $this->element |
|
| 93 | + )); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - $className = $classMap[$type]['class_name']; |
|
| 96 | + $className = $classMap[$type]['class_name']; |
|
| 97 | 97 | |
| 98 | - return new $className($this->config, $arguments); |
|
| 99 | - } |
|
| 98 | + return new $className($this->config, $arguments); |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $this->config = $config; |
| 61 | 61 | |
| 62 | - if (! $this->config->hasKey($element)) { |
|
| 62 | + if ( ! $this->config->hasKey($element)) { |
|
| 63 | 63 | throw new FailedToInstantiateFactoryException(sprintf( |
| 64 | 64 | 'Could not instantiate Factory for unknown Element Type "%1$s".', |
| 65 | 65 | $element |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | $classMap = $this->config[$this->element]; |
| 87 | 87 | |
| 88 | - if (! array_key_exists($type, $classMap)) { |
|
| 88 | + if ( ! array_key_exists($type, $classMap)) { |
|
| 89 | 89 | throw new FailedToInstantiateClassException(sprintf( |
| 90 | 90 | 'Could not create object, unknown Type "%1$s" for "%2$s" elements.', |
| 91 | 91 | $type, |
@@ -22,21 +22,21 @@ |
||
| 22 | 22 | interface TemplateInterface extends Renderable |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Get an array of Sections that are used by this template. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * |
|
| 30 | - * @return array Sections that are used by this template. |
|
| 31 | - */ |
|
| 32 | - public function getUsedSections(); |
|
| 25 | + /** |
|
| 26 | + * Get an array of Sections that are used by this template. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * |
|
| 30 | + * @return array Sections that are used by this template. |
|
| 31 | + */ |
|
| 32 | + public function getUsedSections(); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get the name of the Template. |
|
| 36 | - * |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - * |
|
| 39 | - * @return string Name of the template. |
|
| 40 | - */ |
|
| 41 | - public function getTemplateName(); |
|
| 34 | + /** |
|
| 35 | + * Get the name of the Template. |
|
| 36 | + * |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + * |
|
| 39 | + * @return string Name of the template. |
|
| 40 | + */ |
|
| 41 | + public function getTemplateName(); |
|
| 42 | 42 | } |
@@ -26,115 +26,115 @@ |
||
| 26 | 26 | class ChainMail |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - const DEFAULT_CONFIG = __DIR__ . '/../config/defaults.php'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Configuration Settings. |
|
| 33 | - * |
|
| 34 | - * @since 1.0.0 |
|
| 35 | - * |
|
| 36 | - * @var ConfigInterface |
|
| 37 | - */ |
|
| 38 | - protected $config; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Instantiate a ChainMail object. |
|
| 42 | - * |
|
| 43 | - * @since 1.0.0 |
|
| 44 | - * |
|
| 45 | - * @param ConfigInterface|null $config Optional. Configuration settings. |
|
| 46 | - */ |
|
| 47 | - public function __construct(ConfigInterface $config = null) |
|
| 48 | - { |
|
| 49 | - |
|
| 50 | - $defaults = ConfigFactory::create(include(self::DEFAULT_CONFIG)); |
|
| 51 | - |
|
| 52 | - if (! $config) { |
|
| 53 | - $this->config = $defaults; |
|
| 54 | - |
|
| 55 | - return; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $this->config = ConfigFactory::create(array_merge( |
|
| 59 | - (array)$defaults, |
|
| 60 | - (array)$config) |
|
| 61 | - ); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Render a specific section. |
|
| 66 | - * |
|
| 67 | - * @since 1.0.0 |
|
| 68 | - * |
|
| 69 | - * @param string $sectionType Type of section to render. |
|
| 70 | - * @param array $context The context in which to render the section. |
|
| 71 | - * |
|
| 72 | - * @return string Rendered HTML. |
|
| 73 | - */ |
|
| 74 | - public static function renderSection($sectionType, $context) |
|
| 75 | - { |
|
| 76 | - /** @var SectionInterface $section */ |
|
| 77 | - $section = $context['sections'][$sectionType]; |
|
| 78 | - |
|
| 79 | - return $section->render($context); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Get an array of strings representing the sections that are used by the |
|
| 84 | - * template. |
|
| 85 | - * |
|
| 86 | - * @since 1.0.0 |
|
| 87 | - * |
|
| 88 | - * @param array $context The context in which to render the section. |
|
| 89 | - * |
|
| 90 | - * @return array Array of strings with section types. |
|
| 91 | - */ |
|
| 92 | - public static function getUsedSections($context) |
|
| 93 | - { |
|
| 94 | - /** @var TemplateInterface $template */ |
|
| 95 | - $template = $context['template']; |
|
| 96 | - |
|
| 97 | - return $template->getUsedSections(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Render a all used sections. |
|
| 102 | - * |
|
| 103 | - * @since 1.0.0 |
|
| 104 | - * |
|
| 105 | - * @param array $context The context in which to render the section. |
|
| 106 | - * |
|
| 107 | - * @return string Rendered HTML. |
|
| 108 | - */ |
|
| 109 | - public static function renderSections($context) |
|
| 110 | - { |
|
| 111 | - $output = ''; |
|
| 112 | - |
|
| 113 | - foreach (self::getUsedSections($context) as $section) { |
|
| 114 | - $output .= self::renderSection($section, $context); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return $output; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Create a new mail object. |
|
| 122 | - * |
|
| 123 | - * @since 1.0.0 |
|
| 124 | - * |
|
| 125 | - * @param string|null $format Optional. Format to use. |
|
| 126 | - * @param string|TemplateInterface|null $template Optional. Template to be |
|
| 127 | - * used. |
|
| 128 | - * |
|
| 129 | - * @return MailInterface |
|
| 130 | - */ |
|
| 131 | - public function createMail($format = null, $template = null) |
|
| 132 | - { |
|
| 133 | - $mail_factory = new Factory($this->config, 'mails'); |
|
| 134 | - $mail_class = $this->config->getKey('formats')[$format]['mail']; |
|
| 135 | - $mail = $mail_factory->create($mail_class); |
|
| 136 | - $mail->setTemplate($template); |
|
| 137 | - |
|
| 138 | - return $mail; |
|
| 139 | - } |
|
| 29 | + const DEFAULT_CONFIG = __DIR__ . '/../config/defaults.php'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Configuration Settings. |
|
| 33 | + * |
|
| 34 | + * @since 1.0.0 |
|
| 35 | + * |
|
| 36 | + * @var ConfigInterface |
|
| 37 | + */ |
|
| 38 | + protected $config; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Instantiate a ChainMail object. |
|
| 42 | + * |
|
| 43 | + * @since 1.0.0 |
|
| 44 | + * |
|
| 45 | + * @param ConfigInterface|null $config Optional. Configuration settings. |
|
| 46 | + */ |
|
| 47 | + public function __construct(ConfigInterface $config = null) |
|
| 48 | + { |
|
| 49 | + |
|
| 50 | + $defaults = ConfigFactory::create(include(self::DEFAULT_CONFIG)); |
|
| 51 | + |
|
| 52 | + if (! $config) { |
|
| 53 | + $this->config = $defaults; |
|
| 54 | + |
|
| 55 | + return; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $this->config = ConfigFactory::create(array_merge( |
|
| 59 | + (array)$defaults, |
|
| 60 | + (array)$config) |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Render a specific section. |
|
| 66 | + * |
|
| 67 | + * @since 1.0.0 |
|
| 68 | + * |
|
| 69 | + * @param string $sectionType Type of section to render. |
|
| 70 | + * @param array $context The context in which to render the section. |
|
| 71 | + * |
|
| 72 | + * @return string Rendered HTML. |
|
| 73 | + */ |
|
| 74 | + public static function renderSection($sectionType, $context) |
|
| 75 | + { |
|
| 76 | + /** @var SectionInterface $section */ |
|
| 77 | + $section = $context['sections'][$sectionType]; |
|
| 78 | + |
|
| 79 | + return $section->render($context); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Get an array of strings representing the sections that are used by the |
|
| 84 | + * template. |
|
| 85 | + * |
|
| 86 | + * @since 1.0.0 |
|
| 87 | + * |
|
| 88 | + * @param array $context The context in which to render the section. |
|
| 89 | + * |
|
| 90 | + * @return array Array of strings with section types. |
|
| 91 | + */ |
|
| 92 | + public static function getUsedSections($context) |
|
| 93 | + { |
|
| 94 | + /** @var TemplateInterface $template */ |
|
| 95 | + $template = $context['template']; |
|
| 96 | + |
|
| 97 | + return $template->getUsedSections(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Render a all used sections. |
|
| 102 | + * |
|
| 103 | + * @since 1.0.0 |
|
| 104 | + * |
|
| 105 | + * @param array $context The context in which to render the section. |
|
| 106 | + * |
|
| 107 | + * @return string Rendered HTML. |
|
| 108 | + */ |
|
| 109 | + public static function renderSections($context) |
|
| 110 | + { |
|
| 111 | + $output = ''; |
|
| 112 | + |
|
| 113 | + foreach (self::getUsedSections($context) as $section) { |
|
| 114 | + $output .= self::renderSection($section, $context); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return $output; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Create a new mail object. |
|
| 122 | + * |
|
| 123 | + * @since 1.0.0 |
|
| 124 | + * |
|
| 125 | + * @param string|null $format Optional. Format to use. |
|
| 126 | + * @param string|TemplateInterface|null $template Optional. Template to be |
|
| 127 | + * used. |
|
| 128 | + * |
|
| 129 | + * @return MailInterface |
|
| 130 | + */ |
|
| 131 | + public function createMail($format = null, $template = null) |
|
| 132 | + { |
|
| 133 | + $mail_factory = new Factory($this->config, 'mails'); |
|
| 134 | + $mail_class = $this->config->getKey('formats')[$format]['mail']; |
|
| 135 | + $mail = $mail_factory->create($mail_class); |
|
| 136 | + $mail->setTemplate($template); |
|
| 137 | + |
|
| 138 | + return $mail; |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | class ChainMail |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - const DEFAULT_CONFIG = __DIR__ . '/../config/defaults.php'; |
|
| 29 | + const DEFAULT_CONFIG = __DIR__.'/../config/defaults.php'; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Configuration Settings. |
@@ -49,15 +49,15 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $defaults = ConfigFactory::create(include(self::DEFAULT_CONFIG)); |
| 51 | 51 | |
| 52 | - if (! $config) { |
|
| 52 | + if ( ! $config) { |
|
| 53 | 53 | $this->config = $defaults; |
| 54 | 54 | |
| 55 | 55 | return; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $this->config = ConfigFactory::create(array_merge( |
| 59 | - (array)$defaults, |
|
| 60 | - (array)$config) |
|
| 59 | + (array) $defaults, |
|
| 60 | + (array) $config) |
|
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -22,14 +22,14 @@ |
||
| 22 | 22 | interface Renderable |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Render the current Renderable for a given context. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * |
|
| 30 | - * @param array $context The context in which to render the Renderable. |
|
| 31 | - * |
|
| 32 | - * @return string Rendered output of the Renderable. |
|
| 33 | - */ |
|
| 34 | - public function render(array $context); |
|
| 25 | + /** |
|
| 26 | + * Render the current Renderable for a given context. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * |
|
| 30 | + * @param array $context The context in which to render the Renderable. |
|
| 31 | + * |
|
| 32 | + * @return string Rendered output of the Renderable. |
|
| 33 | + */ |
|
| 34 | + public function render(array $context); |
|
| 35 | 35 | } |
@@ -28,161 +28,161 @@ |
||
| 28 | 28 | abstract class AbstractSection implements SectionInterface |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Name of the Section. |
|
| 33 | - * |
|
| 34 | - * @since 1.0.0 |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected $sectionName; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Configuration Settings. |
|
| 42 | - * |
|
| 43 | - * @since 1.0.0 |
|
| 44 | - * |
|
| 45 | - * @var ConfigInterface |
|
| 46 | - */ |
|
| 47 | - protected $config; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Content of the section. |
|
| 51 | - * |
|
| 52 | - * @since 1.0.0 |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $content; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Instantiate a AbstractSection object. |
|
| 60 | - * |
|
| 61 | - * @since 1.0.0 |
|
| 62 | - * |
|
| 63 | - * @param ConfigInterface $config Configuration settings. |
|
| 64 | - * @param array $arguments Arguments that are passed through |
|
| 65 | - * the constructor. Contained |
|
| 66 | - * elements: string $section, string |
|
| 67 | - * $content |
|
| 68 | - * |
|
| 69 | - * @throws RuntimeException |
|
| 70 | - */ |
|
| 71 | - public function __construct($config, $arguments) |
|
| 72 | - { |
|
| 73 | - $this->config = $config; |
|
| 74 | - list($section, $content) = $arguments; |
|
| 75 | - $this->setSectionName($section); |
|
| 76 | - $this->content = $content; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Get the name of the Section. |
|
| 81 | - * |
|
| 82 | - * @since 1.0.0 |
|
| 83 | - * |
|
| 84 | - * @return string Name of the section. |
|
| 85 | - */ |
|
| 86 | - public function getSectionName() |
|
| 87 | - { |
|
| 88 | - return $this->sectionName; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set the name of the Section. |
|
| 93 | - * |
|
| 94 | - * @since 1.0.0 |
|
| 95 | - * |
|
| 96 | - * @param string|null $section Optional. Name of the section. |
|
| 97 | - * |
|
| 98 | - * @throws FailedToInitialiseSectionException If no section name was passed. |
|
| 99 | - * @throws FailedToInitialiseSectionException If an unknown section name was passed. |
|
| 100 | - */ |
|
| 101 | - protected function setSectionName($section = null) |
|
| 102 | - { |
|
| 103 | - if (null === $section) { |
|
| 104 | - throw new FailedToInitialiseSectionException('Initialised section without passing it a section name.'); |
|
| 105 | - } |
|
| 106 | - if (! array_key_exists($section, $this->config['sections'])) { |
|
| 107 | - throw new FailedToInitialiseSectionException('Initialised section with an unknown section name.'); |
|
| 108 | - } |
|
| 109 | - $this->sectionName = $section; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Render the current Renderable for a given context. |
|
| 114 | - * |
|
| 115 | - * @since 1.0.0 |
|
| 116 | - * |
|
| 117 | - * @param array $context The context in which to render the Renderable. |
|
| 118 | - * |
|
| 119 | - * @return string Rendered output of the Renderable. |
|
| 120 | - * @throws RuntimeException |
|
| 121 | - */ |
|
| 122 | - public function render(array $context) |
|
| 123 | - { |
|
| 124 | - |
|
| 125 | - $viewLocation = $this->getViewLocation($context); |
|
| 126 | - $viewType = $this->config['view_type']; |
|
| 127 | - |
|
| 128 | - $viewFactory = new Factory($this->config, 'view_types'); |
|
| 129 | - $view = $viewFactory->create($viewType, $viewLocation); |
|
| 130 | - |
|
| 131 | - $context['css_class'] = $this->getCSSClass(); |
|
| 132 | - |
|
| 133 | - return $view->render($context, $this->content); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Get the name of the View to use for rendering. |
|
| 138 | - * |
|
| 139 | - * @since 1.0.0 |
|
| 140 | - * |
|
| 141 | - * @return string Name of the view. |
|
| 142 | - */ |
|
| 143 | - protected function getViewName() |
|
| 144 | - { |
|
| 145 | - return $this->config['sections'][$this->getSectionName()]['view_name']; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Get the location of the view that is used for rendering. |
|
| 150 | - * |
|
| 151 | - * @since 1.0.0 |
|
| 152 | - * |
|
| 153 | - * @param array $context Context for which to get the view location. |
|
| 154 | - * |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - protected function getViewLocation(array $context) |
|
| 158 | - { |
|
| 159 | - return $this->getViewRoot() . '/sections/' . $context['format'] . '/' . $this->getViewName(); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get the root location of the view that is used for rendering. |
|
| 164 | - * |
|
| 165 | - * @since 1.0.0 |
|
| 166 | - * |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - protected function getViewRoot() |
|
| 170 | - { |
|
| 171 | - $viewRoots = $this->config['view_root_locations']; |
|
| 172 | - $viewRootKey = $this->config['sections'][$this->getSectionName()]['view_location']; |
|
| 173 | - |
|
| 174 | - return $viewRoots[$viewRootKey]; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Get the CSS class that is used for the section. |
|
| 179 | - * |
|
| 180 | - * @since 1.0.0 |
|
| 181 | - * |
|
| 182 | - * @return string |
|
| 183 | - */ |
|
| 184 | - protected function getCSSClass() |
|
| 185 | - { |
|
| 186 | - return $this->config['sections'][$this->getSectionName()]['css_class']; |
|
| 187 | - } |
|
| 31 | + /** |
|
| 32 | + * Name of the Section. |
|
| 33 | + * |
|
| 34 | + * @since 1.0.0 |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected $sectionName; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Configuration Settings. |
|
| 42 | + * |
|
| 43 | + * @since 1.0.0 |
|
| 44 | + * |
|
| 45 | + * @var ConfigInterface |
|
| 46 | + */ |
|
| 47 | + protected $config; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Content of the section. |
|
| 51 | + * |
|
| 52 | + * @since 1.0.0 |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $content; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Instantiate a AbstractSection object. |
|
| 60 | + * |
|
| 61 | + * @since 1.0.0 |
|
| 62 | + * |
|
| 63 | + * @param ConfigInterface $config Configuration settings. |
|
| 64 | + * @param array $arguments Arguments that are passed through |
|
| 65 | + * the constructor. Contained |
|
| 66 | + * elements: string $section, string |
|
| 67 | + * $content |
|
| 68 | + * |
|
| 69 | + * @throws RuntimeException |
|
| 70 | + */ |
|
| 71 | + public function __construct($config, $arguments) |
|
| 72 | + { |
|
| 73 | + $this->config = $config; |
|
| 74 | + list($section, $content) = $arguments; |
|
| 75 | + $this->setSectionName($section); |
|
| 76 | + $this->content = $content; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Get the name of the Section. |
|
| 81 | + * |
|
| 82 | + * @since 1.0.0 |
|
| 83 | + * |
|
| 84 | + * @return string Name of the section. |
|
| 85 | + */ |
|
| 86 | + public function getSectionName() |
|
| 87 | + { |
|
| 88 | + return $this->sectionName; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set the name of the Section. |
|
| 93 | + * |
|
| 94 | + * @since 1.0.0 |
|
| 95 | + * |
|
| 96 | + * @param string|null $section Optional. Name of the section. |
|
| 97 | + * |
|
| 98 | + * @throws FailedToInitialiseSectionException If no section name was passed. |
|
| 99 | + * @throws FailedToInitialiseSectionException If an unknown section name was passed. |
|
| 100 | + */ |
|
| 101 | + protected function setSectionName($section = null) |
|
| 102 | + { |
|
| 103 | + if (null === $section) { |
|
| 104 | + throw new FailedToInitialiseSectionException('Initialised section without passing it a section name.'); |
|
| 105 | + } |
|
| 106 | + if (! array_key_exists($section, $this->config['sections'])) { |
|
| 107 | + throw new FailedToInitialiseSectionException('Initialised section with an unknown section name.'); |
|
| 108 | + } |
|
| 109 | + $this->sectionName = $section; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Render the current Renderable for a given context. |
|
| 114 | + * |
|
| 115 | + * @since 1.0.0 |
|
| 116 | + * |
|
| 117 | + * @param array $context The context in which to render the Renderable. |
|
| 118 | + * |
|
| 119 | + * @return string Rendered output of the Renderable. |
|
| 120 | + * @throws RuntimeException |
|
| 121 | + */ |
|
| 122 | + public function render(array $context) |
|
| 123 | + { |
|
| 124 | + |
|
| 125 | + $viewLocation = $this->getViewLocation($context); |
|
| 126 | + $viewType = $this->config['view_type']; |
|
| 127 | + |
|
| 128 | + $viewFactory = new Factory($this->config, 'view_types'); |
|
| 129 | + $view = $viewFactory->create($viewType, $viewLocation); |
|
| 130 | + |
|
| 131 | + $context['css_class'] = $this->getCSSClass(); |
|
| 132 | + |
|
| 133 | + return $view->render($context, $this->content); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Get the name of the View to use for rendering. |
|
| 138 | + * |
|
| 139 | + * @since 1.0.0 |
|
| 140 | + * |
|
| 141 | + * @return string Name of the view. |
|
| 142 | + */ |
|
| 143 | + protected function getViewName() |
|
| 144 | + { |
|
| 145 | + return $this->config['sections'][$this->getSectionName()]['view_name']; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Get the location of the view that is used for rendering. |
|
| 150 | + * |
|
| 151 | + * @since 1.0.0 |
|
| 152 | + * |
|
| 153 | + * @param array $context Context for which to get the view location. |
|
| 154 | + * |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + protected function getViewLocation(array $context) |
|
| 158 | + { |
|
| 159 | + return $this->getViewRoot() . '/sections/' . $context['format'] . '/' . $this->getViewName(); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get the root location of the view that is used for rendering. |
|
| 164 | + * |
|
| 165 | + * @since 1.0.0 |
|
| 166 | + * |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + protected function getViewRoot() |
|
| 170 | + { |
|
| 171 | + $viewRoots = $this->config['view_root_locations']; |
|
| 172 | + $viewRootKey = $this->config['sections'][$this->getSectionName()]['view_location']; |
|
| 173 | + |
|
| 174 | + return $viewRoots[$viewRootKey]; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Get the CSS class that is used for the section. |
|
| 179 | + * |
|
| 180 | + * @since 1.0.0 |
|
| 181 | + * |
|
| 182 | + * @return string |
|
| 183 | + */ |
|
| 184 | + protected function getCSSClass() |
|
| 185 | + { |
|
| 186 | + return $this->config['sections'][$this->getSectionName()]['css_class']; |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | if (null === $section) { |
| 104 | 104 | throw new FailedToInitialiseSectionException('Initialised section without passing it a section name.'); |
| 105 | 105 | } |
| 106 | - if (! array_key_exists($section, $this->config['sections'])) { |
|
| 106 | + if ( ! array_key_exists($section, $this->config['sections'])) { |
|
| 107 | 107 | throw new FailedToInitialiseSectionException('Initialised section with an unknown section name.'); |
| 108 | 108 | } |
| 109 | 109 | $this->sectionName = $section; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function getViewLocation(array $context) |
| 158 | 158 | { |
| 159 | - return $this->getViewRoot() . '/sections/' . $context['format'] . '/' . $this->getViewName(); |
|
| 159 | + return $this->getViewRoot().'/sections/'.$context['format'].'/'.$this->getViewName(); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -22,18 +22,18 @@ |
||
| 22 | 22 | class HTMLValidator extends AbstractValidator |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Validate the content for a given context. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * |
|
| 30 | - * @param string $content Content to validate. |
|
| 31 | - * @param array $context Context in which to validate. |
|
| 32 | - * |
|
| 33 | - * @return string Validated content. |
|
| 34 | - */ |
|
| 35 | - public function validate($content, array $context) |
|
| 36 | - { |
|
| 37 | - return $content; |
|
| 38 | - } |
|
| 25 | + /** |
|
| 26 | + * Validate the content for a given context. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * |
|
| 30 | + * @param string $content Content to validate. |
|
| 31 | + * @param array $context Context in which to validate. |
|
| 32 | + * |
|
| 33 | + * @return string Validated content. |
|
| 34 | + */ |
|
| 35 | + public function validate($content, array $context) |
|
| 36 | + { |
|
| 37 | + return $content; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -22,18 +22,18 @@ |
||
| 22 | 22 | class TextValidator extends AbstractValidator |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Validate the content for a given context. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * |
|
| 30 | - * @param string $content Content to validate. |
|
| 31 | - * @param array $context Context in which to validate. |
|
| 32 | - * |
|
| 33 | - * @return string Validated content. |
|
| 34 | - */ |
|
| 35 | - public function validate($content, array $context) |
|
| 36 | - { |
|
| 37 | - return $content; |
|
| 38 | - } |
|
| 25 | + /** |
|
| 26 | + * Validate the content for a given context. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * |
|
| 30 | + * @param string $content Content to validate. |
|
| 31 | + * @param array $context Context in which to validate. |
|
| 32 | + * |
|
| 33 | + * @return string Validated content. |
|
| 34 | + */ |
|
| 35 | + public function validate($content, array $context) |
|
| 36 | + { |
|
| 37 | + return $content; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -22,12 +22,12 @@ |
||
| 22 | 22 | interface SectionInterface extends Renderable |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Get the name of the Section. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * |
|
| 30 | - * @return string Name of the section. |
|
| 31 | - */ |
|
| 32 | - public function getSectionName(); |
|
| 25 | + /** |
|
| 26 | + * Get the name of the Section. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * |
|
| 30 | + * @return string Name of the section. |
|
| 31 | + */ |
|
| 32 | + public function getSectionName(); |
|
| 33 | 33 | } |
@@ -22,15 +22,15 @@ |
||
| 22 | 22 | interface SanitizerInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Sanitize content for a given context. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * |
|
| 30 | - * @param string $content Content to sanitize. |
|
| 31 | - * @param array $context Context in which to sanitize. |
|
| 32 | - * |
|
| 33 | - * @return string Sanitized content. |
|
| 34 | - */ |
|
| 35 | - public function sanitize($content, array $context); |
|
| 25 | + /** |
|
| 26 | + * Sanitize content for a given context. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * |
|
| 30 | + * @param string $content Content to sanitize. |
|
| 31 | + * @param array $context Context in which to sanitize. |
|
| 32 | + * |
|
| 33 | + * @return string Sanitized content. |
|
| 34 | + */ |
|
| 35 | + public function sanitize($content, array $context); |
|
| 36 | 36 | } |