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

  • ChangeOperation
  • Collection
  • FeedEditor
  • FeedEditorElement
  • ImageEditor
  • ImageEditorElement
  • Module
  • MultiEditorElement
  • NodeEditor
  • NodeEditorElement
  • PatronEditor
  • PatronEditorElement
  • PHPEditor
  • PHPEditorElement
  • RawEditor
  • RawEditorElement
  • RTEEditor
  • RTEEditorElement
  • SelectorElement
  • TabbableEditor
  • TabbableEditorElement
  • TabbableEditorRenderer
  • TabbableNewPaneOperation
  • TextEditor
  • TextEditorElement
  • TextmarkEditor
  • TextmarkEditorElement
  • WidgetsEditor
  • WidgetsEditorElement

Interfaces

  • Editor
  • EditorElement

Exceptions

  • EditorAlreadyInstantiated
  • EditorNotDefined
  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\Modules\Editor;
 13 
 14 use ICanBoogie\PropertyNotDefined;
 15 
 16 /**
 17  * Editor collection.
 18  */
 19 class Collection implements \ArrayAccess, \IteratorAggregate
 20 {
 21     /**
 22      * Returns the global editor collection.
 23      *
 24      * The collection is created from the `editors` config and can be altered with an event hook
 25      * on the `Icybee\Modules\Editor\Collection::alter` event.
 26      *
 27      * @param \ICanBoogie\Core $core
 28      *
 29      * @return \Icybee\Modules\Editor\Collection
 30      */
 31     static public function prototype_get_editors(\ICanBoogie\Core $core)
 32     {
 33         $definitions = (array) $core->configs->synthesize('editors', 'merge');
 34         $collection = new static($definitions);
 35 
 36         new Collection\AlterEvent($collection);
 37 
 38         return $collection;
 39     }
 40 
 41     protected $definitions;
 42     protected $editors;
 43 
 44     /**
 45      * Creates the collection.
 46      */
 47     public function __construct(array $definitions=array())
 48     {
 49         $this->definitions = $definitions;
 50     }
 51 
 52     /**
 53      * Checks if a editor exists.
 54      */
 55     public function offsetExists($offset)
 56     {
 57         if ($offset == 'moo') // COMPAT
 58         {
 59             $offset = 'rte';
 60         }
 61         else if ($offset == 'adjustimage')
 62         {
 63             $offset = 'image';
 64         }
 65 
 66         return isset($this->definitions[$offset]);
 67     }
 68 
 69     /**
 70      * Returns the definition of an editor.
 71      *
 72      * @throws EditorNotDefined in attempt to use an undefined editor.
 73      */
 74     public function offsetGet($offset)
 75     {
 76         if ($offset == 'moo') // COMPAT
 77         {
 78             $offset = 'rte';
 79         }
 80         else if ($offset == 'adjustimage')
 81         {
 82             $offset = 'image';
 83         }
 84 
 85         if (isset($this->editors[$offset]))
 86         {
 87             return $this->editors[$offset];
 88         }
 89 
 90         if (!$this->offsetExists($offset))
 91         {
 92             throw new EditorNotDefined($offset);
 93         }
 94 
 95         $class = $this->definitions[$offset];
 96         $editor = new $class;
 97 
 98         return $this->editors[$offset] = $editor;
 99     }
100 
101     /**
102      * Sets the editor definition.
103      *
104      * @throws EditorAlreadyInstantiated if an editor has already been instanciated with a previous
105      * definition.
106      */
107     public function offsetSet($id, $value)
108     {
109         if (isset($this->editors[$id]))
110         {
111             throw new EditorAlreadyInstantiated($id);
112         }
113 
114         $this->definitions[$id] = $value;
115     }
116 
117     /**
118      * Removes an editor definition.
119      *
120      * @throws EditorAlreadyInstantiated if an editor has already been instanciated the definition.
121      */
122     public function offsetUnset($id)
123     {
124         if (isset($this->editors[$id]))
125         {
126             throw new EditorAlreadyInstantiated($id);
127         }
128 
129         unset($this->definitions[$id]);
130     }
131 
132     /**
133      * Returns an iterator for the editor definitions.
134      */
135     public function getIterator()
136     {
137         return new \ArrayIterator($this->definitions);
138     }
139 }
140 
141 /**
142  * Exception thrown in attempt to use an undefined editor.
143  *
144  * @property-read string $editor_id The identifier of the editor.
145  */
146 class EditorNotDefined extends \ICanBoogie\OffsetNotDefined
147 {
148     private $editor_id;
149 
150     public function __construct($editor_id, $code=500, \Exception $previous=null)
151     {
152         $this->editor_id = $editor_id;
153 
154         parent::__construct("Editor not defined: $editor_id.", $code, $previous);
155     }
156 
157     public function __get($property)
158     {
159         if ($property == 'editor_id')
160         {
161             return $this->editor_id;
162         }
163 
164         throw PropertyNotDefined(array($property, $this));
165     }
166 }
167 
168 /**
169  * Exception thrown in attempt to alter a definition that was used to instantiate an editor.
170  *
171  * @property-read string $editor_id The identifier of the editor.
172  */
173 class EditorAlreadyInstantiated extends \RuntimeException
174 {
175     private $editor_id;
176 
177     public function __construct($editor_id, $code=500, \Exception $previous=null)
178     {
179         $this->editor_id = $editor_id;
180 
181         parent::__construct("An editor has already been instantiated: $editor_id.", $code, $previous);
182     }
183 
184     public function __get($property)
185     {
186         if ($property == 'editor_id')
187         {
188             return $this->editor_id;
189         }
190 
191         throw PropertyNotDefined(array($property, $this));
192     }
193 }
194 
195 namespace Icybee\Modules\Editor\Collection;
196 
197 /**
198  * Event class for the `Icybee\Modules\Editor\Collection::alter` event.
199  */
200 class AlterEvent extends \ICanBoogie\Event
201 {
202     /**
203      * The event is constructed with the type `alter`.
204      *
205      * @param \Icybee\Modules\Editor\Collection $target
206      */
207     public function __construct(\Icybee\Modules\Editor\Collection $target)
208     {
209         parent::__construct($target, 'alter');
210     }
211 }
Autodoc API documentation generated by ApiGen 2.8.0