@@ -33,7 +33,7 @@ |
||
| 33 | 33 | * @param string|null $content Content between enclosing shortcodes. |
| 34 | 34 | * @return string The shortcode's HTML output. |
| 35 | 35 | */ |
| 36 | - public function render( $atts, $content = null ); |
|
| 36 | + public function render($atts, $content = null); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Get the shortcode tag. |
@@ -30,5 +30,5 @@ |
||
| 30 | 30 | * @param string $tag Tag of the shortcode. |
| 31 | 31 | * @return array Validated attributes of the shortcode. |
| 32 | 32 | */ |
| 33 | - public function parse_atts( $atts, $tag ); |
|
| 33 | + public function parse_atts($atts, $tag); |
|
| 34 | 34 | } |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * attributes. |
| 38 | 38 | * @throws RuntimeException If the config could not be processed. |
| 39 | 39 | */ |
| 40 | - public function __construct( ConfigInterface $config ) { |
|
| 41 | - $this->processConfig( $config ); |
|
| 40 | + public function __construct(ConfigInterface $config) { |
|
| 41 | + $this->processConfig($config); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * @param string $tag Tag of the shortcode. |
| 51 | 51 | * @return array Validated attributes of the shortcode. |
| 52 | 52 | */ |
| 53 | - public function parse_atts( $atts, $tag ) { |
|
| 53 | + public function parse_atts($atts, $tag) { |
|
| 54 | 54 | $atts = \shortcode_atts( |
| 55 | 55 | $this->default_atts(), |
| 56 | - $this->validated_atts( (array) $atts ), |
|
| 56 | + $this->validated_atts((array) $atts), |
|
| 57 | 57 | $tag |
| 58 | 58 | ); |
| 59 | 59 | |
@@ -71,14 +71,14 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | $atts = array(); |
| 73 | 73 | |
| 74 | - if ( ! $this->hasConfigKey( 'atts' ) ) { |
|
| 74 | + if ( ! $this->hasConfigKey('atts')) { |
|
| 75 | 75 | return $atts; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $atts_config = $this->getConfigKey( 'atts' ); |
|
| 79 | - array_walk( $atts_config, |
|
| 80 | - function ( $att_properties, $att_label ) use ( &$atts ) { |
|
| 81 | - $atts[ $att_label ] = $att_properties['default']; |
|
| 78 | + $atts_config = $this->getConfigKey('atts'); |
|
| 79 | + array_walk($atts_config, |
|
| 80 | + function($att_properties, $att_label) use (&$atts) { |
|
| 81 | + $atts[$att_label] = $att_properties['default']; |
|
| 82 | 82 | } |
| 83 | 83 | ); |
| 84 | 84 | |
@@ -94,18 +94,18 @@ discard block |
||
| 94 | 94 | * @param array $atts Attributes that were passed to the shortcode. |
| 95 | 95 | * @return array Validated attributes. |
| 96 | 96 | */ |
| 97 | - protected function validated_atts( $atts ) { |
|
| 97 | + protected function validated_atts($atts) { |
|
| 98 | 98 | |
| 99 | - if ( ! $this->hasConfigKey( 'atts' ) ) { |
|
| 99 | + if ( ! $this->hasConfigKey('atts')) { |
|
| 100 | 100 | return $atts; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $atts_config = $this->getConfigKey( 'atts' ); |
|
| 104 | - array_walk( $atts_config, |
|
| 105 | - function ( $att_properties, $att_label ) use ( &$atts ) { |
|
| 106 | - if ( array_key_exists( $att_label, $atts ) ) { |
|
| 103 | + $atts_config = $this->getConfigKey('atts'); |
|
| 104 | + array_walk($atts_config, |
|
| 105 | + function($att_properties, $att_label) use (&$atts) { |
|
| 106 | + if (array_key_exists($att_label, $atts)) { |
|
| 107 | 107 | $validate_function = $att_properties['validate']; |
| 108 | - $atts[ $att_label ] = $validate_function( $atts[ $att_label ] ); |
|
| 108 | + $atts[$att_label] = $validate_function($atts[$att_label]); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | ); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @var ShortcodeInterface[] |
| 59 | 59 | */ |
| 60 | - protected $shortcodes = [ ]; |
|
| 60 | + protected $shortcodes = []; |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * DependencyManagerInterface implementation. |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @var ShortcodeUIInterface[] |
| 77 | 77 | */ |
| 78 | - protected $shortcode_uis = [ ]; |
|
| 78 | + protected $shortcode_uis = []; |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Instantiate a ShortcodeManager object. |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | ConfigInterface $config, |
| 94 | 94 | DependencyManagerInterface $dependencies |
| 95 | 95 | ) {
|
| 96 | - $this->processConfig( $config ); |
|
| 96 | + $this->processConfig($config); |
|
| 97 | 97 | $this->dependencies = $dependencies; |
| 98 | 98 | |
| 99 | 99 | $this->init_shortcodes(); |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | * @since 0.1.0 |
| 106 | 106 | */ |
| 107 | 107 | public function init_shortcodes() {
|
| 108 | - foreach ( $this->getConfigKeys() as $tag ) {
|
|
| 109 | - $this->init_shortcode( $tag ); |
|
| 108 | + foreach ($this->getConfigKeys() as $tag) {
|
|
| 109 | + $this->init_shortcode($tag); |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
@@ -117,22 +117,22 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @param string $tag The tag of the shortcode to register. |
| 119 | 119 | */ |
| 120 | - protected function init_shortcode( $tag ) {
|
|
| 121 | - $shortcode_class = $this->get_shortcode_class( $tag ); |
|
| 122 | - $shortcode_atts_parser = $this->get_shortcode_atts_parser_class( $tag ); |
|
| 120 | + protected function init_shortcode($tag) {
|
|
| 121 | + $shortcode_class = $this->get_shortcode_class($tag); |
|
| 122 | + $shortcode_atts_parser = $this->get_shortcode_atts_parser_class($tag); |
|
| 123 | 123 | |
| 124 | 124 | $atts_parser = new $shortcode_atts_parser( |
| 125 | - $this->config->getSubConfig( $tag ) |
|
| 125 | + $this->config->getSubConfig($tag) |
|
| 126 | 126 | ); |
| 127 | 127 | $this->shortcodes[] = new $shortcode_class( |
| 128 | 128 | $tag, |
| 129 | - $this->config->getSubConfig( $tag ), |
|
| 129 | + $this->config->getSubConfig($tag), |
|
| 130 | 130 | $atts_parser, |
| 131 | 131 | $this->dependencies |
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | - if ( $this->hasConfigKey( $tag, self::KEY_UI ) ) {
|
|
| 135 | - $this->init_shortcode_ui( $tag ); |
|
| 134 | + if ($this->hasConfigKey($tag, self::KEY_UI)) {
|
|
| 135 | + $this->init_shortcode_ui($tag); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | * @param string $tag Shortcode tag to get the class for. |
| 145 | 145 | * @return string Class name of the Shortcode. |
| 146 | 146 | */ |
| 147 | - protected function get_shortcode_class( $tag ) {
|
|
| 148 | - $shortcode_class = $this->hasConfigKey( $tag, self::KEY_CUSTOM_CLASS ) |
|
| 149 | - ? $this->getConfigKey( $tag, self::KEY_CUSTOM_CLASS ) |
|
| 147 | + protected function get_shortcode_class($tag) {
|
|
| 148 | + $shortcode_class = $this->hasConfigKey($tag, self::KEY_CUSTOM_CLASS) |
|
| 149 | + ? $this->getConfigKey($tag, self::KEY_CUSTOM_CLASS) |
|
| 150 | 150 | : self::DEFAULT_SHORTCODE; |
| 151 | 151 | return $shortcode_class; |
| 152 | 152 | } |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | * @param string $tag Shortcode tag to get the class for. |
| 161 | 161 | * @return string Class name of the ShortcodeAttsParser. |
| 162 | 162 | */ |
| 163 | - protected function get_shortcode_atts_parser_class( $tag ) {
|
|
| 164 | - $atts_parser = $this->hasConfigKey( $tag, self::KEY_CUSTOM_ATTS_PARSER ) |
|
| 165 | - ? $this->getConfigKey( $tag, self::KEY_CUSTOM_ATTS_PARSER ) |
|
| 163 | + protected function get_shortcode_atts_parser_class($tag) {
|
|
| 164 | + $atts_parser = $this->hasConfigKey($tag, self::KEY_CUSTOM_ATTS_PARSER) |
|
| 165 | + ? $this->getConfigKey($tag, self::KEY_CUSTOM_ATTS_PARSER) |
|
| 166 | 166 | : self::DEFAULT_SHORTCODE_ATTS_PARSER; |
| 167 | 167 | return $atts_parser; |
| 168 | 168 | } |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @param string $tag The tag of the shortcode to register the UI for. |
| 176 | 176 | */ |
| 177 | - protected function init_shortcode_ui( $tag ) {
|
|
| 178 | - $shortcode_ui_class = $this->get_shortcode_ui_class( $tag ); |
|
| 177 | + protected function init_shortcode_ui($tag) {
|
|
| 178 | + $shortcode_ui_class = $this->get_shortcode_ui_class($tag); |
|
| 179 | 179 | |
| 180 | 180 | $this->shortcode_uis[] = new $shortcode_ui_class( |
| 181 | 181 | $tag, |
| 182 | - $this->config->getSubConfig( $tag, self::KEY_UI ), |
|
| 182 | + $this->config->getSubConfig($tag, self::KEY_UI), |
|
| 183 | 183 | $this->dependencies |
| 184 | 184 | ); |
| 185 | 185 | } |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | * @param string $tag Configuration settings. |
| 193 | 193 | * @return string Class name of the ShortcodeUI. |
| 194 | 194 | */ |
| 195 | - protected function get_shortcode_ui_class( $tag ) {
|
|
| 196 | - $ui_class = $this->hasConfigKey( $tag, self::KEY_CUSTOM_UI ) |
|
| 197 | - ? $this->getConfigKey( $tag, self::KEY_CUSTOM_UI ) |
|
| 195 | + protected function get_shortcode_ui_class($tag) {
|
|
| 196 | + $ui_class = $this->hasConfigKey($tag, self::KEY_CUSTOM_UI) |
|
| 197 | + ? $this->getConfigKey($tag, self::KEY_CUSTOM_UI) |
|
| 198 | 198 | : self::DEFAULT_SHORTCODE_UI; |
| 199 | 199 | return $ui_class; |
| 200 | 200 | } |
@@ -208,18 +208,18 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | public function register() {
|
| 210 | 210 | $template = $this->get_page_template(); |
| 211 | - $context = [ 'page_template' => $template ]; |
|
| 211 | + $context = ['page_template' => $template]; |
|
| 212 | 212 | |
| 213 | - array_walk( $this->shortcodes, |
|
| 214 | - function ( $shortcode ) use ( $context ) {
|
|
| 213 | + array_walk($this->shortcodes, |
|
| 214 | + function($shortcode) use ($context) {
|
|
| 215 | 215 | /** @var ShortcodeInterface $shortcode */ |
| 216 | - $shortcode->register( $context ); |
|
| 216 | + $shortcode->register($context); |
|
| 217 | 217 | } ); |
| 218 | 218 | |
| 219 | 219 | // This hook only gets fired when Shortcode UI plugin is active. |
| 220 | 220 | \add_action( |
| 221 | 221 | 'register_shortcode_ui', |
| 222 | - [ $this, 'register_shortcode_ui', ] |
|
| 222 | + [$this, 'register_shortcode_ui', ] |
|
| 223 | 223 | ); |
| 224 | 224 | } |
| 225 | 225 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | protected function get_page_template() {
|
| 234 | 234 | $template = str_replace( |
| 235 | - \trailingslashit( \get_stylesheet_directory() ), |
|
| 235 | + \trailingslashit(\get_stylesheet_directory()), |
|
| 236 | 236 | '', |
| 237 | 237 | \get_page_template() |
| 238 | 238 | ); |
@@ -246,12 +246,12 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | public function register_shortcode_ui() {
|
| 248 | 248 | $template = $this->get_page_template(); |
| 249 | - $context = [ 'page_template' => $template ]; |
|
| 249 | + $context = ['page_template' => $template]; |
|
| 250 | 250 | |
| 251 | - array_walk( $this->shortcode_uis, |
|
| 252 | - function ( $shortcode_ui ) use ( $context ) {
|
|
| 251 | + array_walk($this->shortcode_uis, |
|
| 252 | + function($shortcode_ui) use ($context) {
|
|
| 253 | 253 | /** @var ShortcodeUIInterface $shortcode_ui */ |
| 254 | - $shortcode_ui->register( $context ); |
|
| 254 | + $shortcode_ui->register($context); |
|
| 255 | 255 | } |
| 256 | 256 | ); |
| 257 | 257 | } |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | ConfigInterface $config, |
| 64 | 64 | DependencyManagerInterface $dependencies |
| 65 | 65 | ) { |
| 66 | - Assert\that( $shortcode_tag )->string()->notEmpty(); |
|
| 66 | + Assert\that($shortcode_tag)->string()->notEmpty(); |
|
| 67 | 67 | |
| 68 | - $this->processConfig( $config ); |
|
| 68 | + $this->processConfig($config); |
|
| 69 | 69 | |
| 70 | 70 | $this->shortcode_tag = $shortcode_tag; |
| 71 | 71 | $this->dependencies = $dependencies; |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | * @param mixed $context Data about the context in which the call is made. |
| 80 | 80 | * @return void |
| 81 | 81 | */ |
| 82 | - public function register( $context = null ) { |
|
| 83 | - if ( ! $this->is_needed() ) { |
|
| 82 | + public function register($context = null) { |
|
| 83 | + if ( ! $this->is_needed()) { |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -98,15 +98,15 @@ discard block |
||
| 98 | 98 | * @param mixed $context Data about the context in which the call is made. |
| 99 | 99 | * @return boolean Whether the shortcode UI is needed or not. |
| 100 | 100 | */ |
| 101 | - protected function is_needed( $context = null ) { |
|
| 101 | + protected function is_needed($context = null) { |
|
| 102 | 102 | |
| 103 | - $is_needed = $this->hasConfigKey( 'is_needed' ) |
|
| 104 | - ? $this->getConfigKey( 'is_needed' ) |
|
| 103 | + $is_needed = $this->hasConfigKey('is_needed') |
|
| 104 | + ? $this->getConfigKey('is_needed') |
|
| 105 | 105 | : false; |
| 106 | 106 | |
| 107 | 107 | // Return true if a callable 'is_needed' evaluates to true. |
| 108 | - if ( is_callable( $is_needed ) ) { |
|
| 109 | - return $is_needed( $context ); |
|
| 108 | + if (is_callable($is_needed)) { |
|
| 109 | + return $is_needed($context); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | return (bool) $is_needed; |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | DependencyManager $dependencies = null |
| 82 | 82 | ) {
|
| 83 | 83 | |
| 84 | - Assert\that( $shortcode_tag )->string()->notEmpty(); |
|
| 84 | + Assert\that($shortcode_tag)->string()->notEmpty(); |
|
| 85 | 85 | |
| 86 | - $this->processConfig( $config ); |
|
| 86 | + $this->processConfig($config); |
|
| 87 | 87 | |
| 88 | 88 | $this->shortcode_tag = $shortcode_tag; |
| 89 | 89 | $this->atts_parser = $atts_parser; |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | * (Not used with Shortcode class) |
| 100 | 100 | * @return void |
| 101 | 101 | */ |
| 102 | - public function register( $args = null ) {
|
|
| 103 | - if ( ! $this->is_needed( $args ) ) {
|
|
| 102 | + public function register($args = null) {
|
|
| 103 | + if ( ! $this->is_needed($args)) {
|
|
| 104 | 104 | return; |
| 105 | 105 | } |
| 106 | - \add_shortcode( $this->get_tag(), [ $this, 'render' ] ); |
|
| 106 | + \add_shortcode($this->get_tag(), [$this, 'render']); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | * @param mixed $context Data about the context in which the call is made. |
| 115 | 115 | * @return boolean Whether the shortcode is needed or not. |
| 116 | 116 | */ |
| 117 | - protected function is_needed( $context = null ) {
|
|
| 117 | + protected function is_needed($context = null) {
|
|
| 118 | 118 | |
| 119 | - $is_needed = $this->hasConfigKey( 'is_needed' ) |
|
| 120 | - ? $this->getConfigKey( 'is_needed' ) |
|
| 119 | + $is_needed = $this->hasConfigKey('is_needed')
|
|
| 120 | + ? $this->getConfigKey('is_needed')
|
|
| 121 | 121 | : false; |
| 122 | 122 | |
| 123 | - if ( is_callable( $is_needed ) ) {
|
|
| 124 | - return $is_needed( $context ); |
|
| 123 | + if (is_callable($is_needed)) {
|
|
| 124 | + return $is_needed($context); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | return (bool) $is_needed; |
@@ -153,22 +153,22 @@ discard block |
||
| 153 | 153 | * render. |
| 154 | 154 | * @return string The shortcode's HTML output. |
| 155 | 155 | */ |
| 156 | - public function render( $atts, $content = null, $tag = null ) {
|
|
| 157 | - $atts = $this->atts_parser->parse_atts( $atts, $this->get_tag() ); |
|
| 156 | + public function render($atts, $content = null, $tag = null) {
|
|
| 157 | + $atts = $this->atts_parser->parse_atts($atts, $this->get_tag()); |
|
| 158 | 158 | |
| 159 | - if ( $this->dependencies ) {
|
|
| 160 | - $this->dependencies->enqueue( $atts ); |
|
| 159 | + if ($this->dependencies) {
|
|
| 160 | + $this->dependencies->enqueue($atts); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if ( ! $this->hasConfigKey( 'view' ) ) {
|
|
| 163 | + if ( ! $this->hasConfigKey('view')) {
|
|
| 164 | 164 | return ''; |
| 165 | 165 | } |
| 166 | - $view = $this->getConfigKey( 'view' ); |
|
| 166 | + $view = $this->getConfigKey('view');
|
|
| 167 | 167 | |
| 168 | - Assert\that( $view )->string()->notEmpty()->file(); |
|
| 168 | + Assert\that($view)->string()->notEmpty()->file(); |
|
| 169 | 169 | |
| 170 | 170 | ob_start(); |
| 171 | - include( $this->config['view'] ); |
|
| 171 | + include($this->config['view']); |
|
| 172 | 172 | |
| 173 | 173 | return ob_get_clean(); |
| 174 | 174 | } |