Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • AdminDecorator
  • AdminIndexController
  • BlockController
  • BlockDecorator
  • ConfigBlock
  • ConfigController
  • ConfigOperation
  • Core
  • DeleteBlock
  • DeleteController
  • Document
  • DocumentDecorator
  • EditBlock
  • EditController
  • FormBlock
  • Hooks
  • InterlockBlock
  • Kses
  • ManageBlock
  • Module
  • Modules
  • StatsDecorator

Constants

  • OPERATION_SAVE_MODE
  • OPERATION_SAVE_MODE_CONTINUE
  • OPERATION_SAVE_MODE_DISPLAY
  • OPERATION_SAVE_MODE_LIST
  • OPERATION_SAVE_MODE_NEW

Functions

  • slugize
  • start
  • strip_stopwords
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee;
 13 
 14 use ICanBoogie\HTTP\Request;
 15 use ICanBoogie\Route;
 16 
 17 use Brickrouge\Element;
 18 
 19 /**
 20  * Returns a decorated block.
 21  *
 22  * The `decorate_flags` param is used to specify how the block is to be decorated. The following
 23  * flags are defined:
 24  *
 25  * - {@link DECORATE_WITH_BLOCK}: Decorate the component with a {@link BlockDecorator} instance.
 26  * - {@link DECORATE_WITH_ADMIN}: Decorate the component with a {@link AdminDecorator} instance.
 27  * - {@link DECORATE_WITH_DOCUMENT} Decorate the component with a {@link DocumentDecorator} instance.
 28  */
 29 class BlockController extends \ICanBoogie\Routing\Controller
 30 {
 31     const DECORATE_WITH_BLOCK = 1;
 32     const DECORATE_WITH_ADMIN = 2;
 33     const DECORATE_WITH_DOCUMENT = 4;
 34 
 35     protected $decorate_flags;
 36     protected $request;
 37     protected $block_name;
 38 
 39     public function __construct(Route $route)
 40     {
 41         $this->decorate_flags = self::DECORATE_WITH_BLOCK | self::DECORATE_WITH_ADMIN | self::DECORATE_WITH_DOCUMENT;
 42 
 43         parent::__construct($route);
 44     }
 45 
 46     /**
 47      * If the `decorate_flags` param is defined the {@link $decorate_flags} property is updated.
 48      */
 49     public function __invoke(Request $request)
 50     {
 51         $this->request = $request;
 52         $this->control();
 53 
 54         $flags = $request['decorate_flags'];
 55 
 56         if ($flags === null)
 57         {
 58             $flags = $this->decorate_flags;
 59         }
 60 
 61         return $this->decorate($this->get_component(), $flags);
 62     }
 63 
 64     /**
 65      * Controls the user access to the block.
 66      *
 67      * @throws \ICanBoogie\PermissionRequired if the user doesn't have at least the
 68      * {@link Module::PERMISSION_ACCESS} permission.
 69      */
 70     protected function control()
 71     {
 72         if (!$this->control_permission(Module::PERMISSION_ACCESS))
 73         {
 74             throw new \ICanBoogie\PermissionRequired();
 75         }
 76     }
 77 
 78     protected function control_permission($permission)
 79     {
 80         global $core;
 81 
 82         $route = $this->route;
 83         $module = $core->modules[$route->module];
 84 
 85         return $core->user->has_permission(Module::PERMISSION_ACCESS, $module);
 86     }
 87 
 88     /**
 89      * Returns the component.
 90      *
 91      * The `getBlock()` method of the target module is used to retrieve the component.
 92      *
 93      * @return mixed
 94      */
 95     protected function get_component()
 96     {
 97         global $core;
 98 
 99         $route = $this->route;
100         $module = $core->modules[$route->module];
101         $args = [ $route->block ];
102 
103         foreach ($this->request->path_params as $param => $value)
104         {
105             if (is_numeric($param))
106             {
107                 $args[] = $value;
108             }
109         }
110 
111         return call_user_func_array([ $module, 'getBlock' ], $args);
112     }
113 
114     /**
115      * Decorates the component.
116      *
117      * @param mixed $component The component to decorate.
118      * @param int $flags The flags describing how the component is to be decorated.
119      *
120      * @return mixed
121      */
122     protected function decorate($component, $flags)
123     {
124         if ($flags & self::DECORATE_WITH_BLOCK)
125         {
126             $route = $this->route;
127             $component = $this->decorate_with_block($component);
128         }
129 
130         if ($flags & self::DECORATE_WITH_ADMIN)
131         {
132             $component = $this->decorate_with_admin($component);
133         }
134 
135         if ($flags & self::DECORATE_WITH_DOCUMENT)
136         {
137             $component = $this->decorate_with_document($component);
138         }
139 
140         return $component;
141     }
142 
143     /**
144      * Decorate a component with an instance of {@link BlockDecorator}.
145      *
146      * @param mixed $component
147      *
148      * @return \Icybee\BlockDecorator
149      */
150     protected function decorate_with_block($component)
151     {
152         $route = $this->route;
153 
154         return new BlockDecorator($component, $route->block, $route->module);
155     }
156 
157     /**
158      * Decorate a component with an instance of {@link AdminDecorator}.
159      *
160      * @param mixed $component
161      *
162      * @return \Icybee\AdminDecorator
163      */
164     protected function decorate_with_admin($component)
165     {
166         return new AdminDecorator($component);
167     }
168 
169     /**
170      * Decorates a component with an instance of {@link DocumentDecorator}.
171      *
172      * @param mixed $component
173      *
174      * @return \Icybee\DocumentDecorator
175      */
176     protected function decorate_with_document($component)
177     {
178         return new DocumentDecorator($component);
179     }
180 }
181 
182 /**
183  * Decorates a component with a _block element_.
184  *
185  * The component is wrapped in a `div.block.block--<name>.block--<module>--<name>` element. Where
186  * `<name>` is the normalized name of the block, and `<module>` is the normalized identifier of
187  * the module that created the component.
188  */
189 class BlockDecorator extends \Brickrouge\Decorator
190 {
191     /**
192      * Name of the block.
193      *
194      * @var string
195      */
196     protected $block_name;
197 
198     /**
199      * The identifier of the module providing the block.
200      *
201      * @var string
202      */
203     protected $module_id;
204 
205     /**
206      * Initialiazes the {@link $block_name} and {@link $module_id} properties.
207      *
208      * @param mixed $block The block to decorate.
209      * @param string $block_name The name of the block.
210      * @param string $module_id The itentifier of the module providing the block.
211      */
212     public function __construct($block, $block_name, $module_id)
213     {
214         $this->block_name = $block_name;
215         $this->module_id = $module_id;
216 
217         parent::__construct($block);
218     }
219 
220     public function render()
221     {
222         $normalized_block_name = \Brickrouge\normalize($this->block_name);
223         $normalized_module_id = \Brickrouge\normalize($this->module_id);
224 
225         return new Element('div', [
226 
227             Element::INNER_HTML => $this->component,
228 
229             'class' => "block block--{$normalized_block_name} block--{$normalized_module_id}--{$normalized_block_name}"
230 
231         ]);
232     }
233 }
Autodoc API documentation generated by ApiGen 2.8.0