Factory.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Shortcode factory for the [aam] shortcode |
| 12 | * |
| 13 | * @since 6.6.0 https://github.com/aamplugin/advanced-access-manager/issues/90 |
| 14 | * @since 6.0.0 Initial implementation of the class |
| 15 | * |
| 16 | * @package AAM |
| 17 | * @version 6.6.0 |
| 18 | */ |
| 19 | class AAM_Shortcode_Factory |
| 20 | { |
| 21 | |
| 22 | /** |
| 23 | * Shortcode handler based on the provided attributes |
| 24 | * |
| 25 | * @var AAM_Core_Contract_ShortcodeInterface |
| 26 | * |
| 27 | * @access protected |
| 28 | * @version 6.0.0 |
| 29 | */ |
| 30 | protected $handler = null; |
| 31 | |
| 32 | /** |
| 33 | * Initialize shortcode factory |
| 34 | * |
| 35 | * @param array $args |
| 36 | * @param string $content |
| 37 | * |
| 38 | * @return void |
| 39 | * |
| 40 | * @since 6.6.0 https://github.com/aamplugin/advanced-access-manager/issues/90 |
| 41 | * @since 6.0.0 Initial implementation of the method |
| 42 | * |
| 43 | * @access public |
| 44 | * @version 6.6.0 |
| 45 | */ |
| 46 | public function __construct($args, $content) |
| 47 | { |
| 48 | $cnt = strtolower(!empty($args['context']) ? $args['context'] : 'content'); |
| 49 | |
| 50 | if ($cnt === 'content') { |
| 51 | $this->handler = new AAM_Shortcode_Handler_Content($args, $content); |
| 52 | } elseif ($cnt === 'loginredirect') { |
| 53 | $this->handler = new AAM_Shortcode_Handler_LoginRedirect($args, $content); |
| 54 | } elseif ($cnt === 'loginform') { |
| 55 | $this->handler = new AAM_Shortcode_Handler_LoginForm($args); |
| 56 | } else { |
| 57 | $this->handler = apply_filters( |
| 58 | 'aam_shortcode_filter', null, $cnt, $args, $content |
| 59 | ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Process the short-code |
| 65 | * |
| 66 | * @return string |
| 67 | * |
| 68 | * @access public |
| 69 | * @version 6.0.0 |
| 70 | */ |
| 71 | public function process() |
| 72 | { |
| 73 | $content = null; |
| 74 | |
| 75 | if (is_a($this->handler, 'AAM_Core_Contract_ShortcodeInterface')) { |
| 76 | $content = $this->handler->run(); |
| 77 | } else { |
| 78 | _doing_it_wrong( |
| 79 | __CLASS__ . '::' . __METHOD__, |
| 80 | 'No valid strategy found for the given context', |
| 81 | AAM_VERSION |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | return $content; |
| 86 | } |
| 87 | |
| 88 | } |