Overview

Namespaces

  • None
  • PHP
  • picon

Classes

  • AbstractAjaxBehaviour
  • AbstractAssociatedMarkupSource
  • AbstractBehaviour
  • AbstractCallableOption
  • AbstractChoice
  • AbstractColumn
  • AbstractContextLoader
  • AbstractDatabaseDriver
  • AbstractInjectedDataProvider
  • AbstractJQueryBehaviour
  • AbstractJQueryUIBehaviour
  • AbstractLink
  • AbstractMarkupSource
  • AbstractMultipleChoice
  • AbstractOption
  • AbstractPageClassAuthorisationStrategy
  • AbstractRepeater
  • AbstractSingleChoice
  • AbstractTextComponent
  • AbstractToolbar
  • AbstractValidator
  • AjaxButton
  • AjaxEventBehaviour
  • AjaxFormComponentUpdateBehavior
  • AjaxFormSubmitBehavior
  • AjaxLink
  • AjaxRequestTarget
  • AllowAllAuthorisationStrategy
  • AnnotationRule
  • ApplicationConfigLoadListener
  • ApplicationContext
  • ApplicationContextLoadListener
  • ApplicationInitializer
  • ApplicationInitializerConfigLoadListenerCollection
  • ApplicationInitializerContextLoadListenerCollection
  • ApplicationProfile
  • Args
  • ArrayModel
  • ArrayOption
  • AttributeAppender
  • AttributeModifier
  • AutoContextLoader
  • AutoLoader
  • BasicModel
  • BooleanModel
  • BooleanOption
  • Border
  • BorderMarkupSourcingStratagy
  • BorderResolver
  • Button
  • CacheManager
  • CallbackAjaxCallDecorator
  • CallbackColumn
  • CallbackFunctionOption
  • CallbackOption
  • CallbackRowMapper
  • Check
  • CheckBox
  • CheckBoxGroup
  • CheckChoice
  • ChoiceRenderer
  • ClassNameRule
  • ClassNamespaceRule
  • ClassScanner
  • Comment
  • ComonDomainBase
  • Component
  • ComponentAfterRenderListenerCollection
  • ComponentAuthorisationListener
  • ComponentBeforeRenderListenerCollection
  • ComponentInitializationListenerCollection
  • ComponentInjector
  • ComponentInstantiationListenerCollection
  • ComponentRenderHeadListenerCollection
  • ComponentResolverHelper
  • ComponentTag
  • CompoundPropertyModel
  • Config
  • ConfigLoader
  • ContextLoaderFactory
  • DaoSupport
  • DataBaseTemplate
  • DataGridView
  • DataSource
  • DataSourceConfig
  • DataSourceFactory
  • DataSourceType
  • DataTable
  • DateField
  • DatePickerBehaviour
  • DefaultDataTable
  • DefaultJQueryUIBehaviour
  • DefaultMarkupSource
  • DefaultNotAuthorisedListener
  • DialogBehavior
  • DirectToPageComponentNotAuthorisedListener
  • DraggableBehaviour
  • DropDown
  • EmailAddressValidator
  • EmptyPanel
  • Enum
  • ExceptionPageRequestTarget
  • ExtendResolver
  • FeedbackMessage
  • FeedbackModel
  • FeedbackPanel
  • FileModel
  • FileUploadField
  • Form
  • FormComponent
  • FormComponentLabel
  • FormComponentPanel
  • FunctionOption
  • GridItem
  • GridView
  • HeaderContainer
  • HeaderPartContainer
  • HeaderResolver
  • HeaderResponse
  • HeaderToolbar
  • IdenticalValueValidator
  • Identifier
  • Injector
  • JQueryRenderHeadListener
  • JQueryUIRenderHeadListener
  • Label
  • LabeledMarkupContainer
  • Link
  • ListenerCollection
  • ListenerRequestResolver
  • ListenerRequestTarget
  • ListItem
  • ListMultiple
  • ListView
  • Localizer
  • ManualContextLoader
  • MarkupContainer
  • MarkupElement
  • MarkupLoader
  • MarkupParser
  • MarkupUtils
  • MaximumLengthValidator
  • MaximumValidator
  • MinimumLengthValidator
  • MinimumValidator
  • ModalWindow
  • MySqlDriver
  • MySqliDriver
  • NavigationLink
  • NavigationToolbar
  • Navigator
  • NumbericOption
  • NumericValidator
  • Objects
  • Options
  • PageInstanceRequestResolver
  • PageInstanceRequestTarget
  • PageMap
  • PageMapInitializationListenerCollection
  • PageNotFoundPage
  • PageNotFoundRequestTarget
  • PageRequestResolver
  • PageRequestTarget
  • PageRequestWithListenerTarget
  • PaginatingGridView
  • Panel
  • PanelMarkupSource
  • PanelResolver
  • PasswordField
  • PatternValidator
  • PiconApplication
  • PiconErrorHandler
  • PiconSerializer
  • PiconTag
  • PopupSettings
  • PropertyColumn
  • PropertyModel
  • PropertyOption
  • PropertyResolver
  • Radio
  • RadioChoice
  • RadioGroup
  • RangeLengthValidator
  • RangeValidator
  • RedirectRequestTarget
  • RepeatingView
  • RequestCycle
  • RequestResolverCollection
  • RequiredTextField
  • ResourceReference
  • ResourceRequestResolver
  • ResourceRequestTarget
  • SerializableClosure
  • SortableBehavior
  • StaticTabPanel
  • StringValidator
  • SubClassRule
  • Tab
  • TabCollection
  • TabPanel
  • TextArea
  • TextElement
  • TextField
  • TransparentMarkupContainer
  • ValidatableFormComponentWrapper
  • ValidationResponse
  • WebApplicationSecuritySettings
  • WebComponent
  • WebPage
  • WebRequest
  • WebResponse
  • WrappedCompoundModel
  • XMLDocument
  • XMLParser
  • XMLTag
  • XmlTagType

Interfaces

  • AjaxCallDecorator
  • ApplicationInitializerConfigLoadListener
  • ApplicationInitializerContextLoadListener
  • AuthorisationStrategy
  • Behaviour
  • BehaviourListener
  • CallDecoratorWrapper
  • ChoiceGroup
  • ClassScannerRule
  • Column
  • ComponentAfterRenderListener
  • ComponentAwareModel
  • ComponentBeforeRenderListener
  • ComponentInheritedModel
  • ComponentInitializationListener
  • ComponentInstantiationListener
  • ComponentNotAuthorisedListener
  • ComponentRenderHeadListener
  • ComponentResolver
  • CompoundModel
  • DatabaseDriver
  • DataBaseOperations
  • DataProvider
  • Detachable
  • Equalable
  • FormSubmitListener
  • FormSubmitter
  • Identifiable
  • InitializingBean
  • InjectOnWakeup
  • LinkListener
  • Listener
  • MarkupSource
  • Model
  • Pageable
  • PageMapInitializationListener
  • Request
  • RequestablePage
  • RequestResolver
  • RequestTarget
  • Response
  • RowMapper
  • Validatable
  • Validator
  • XmlElement

Exceptions

  • ConfigException
  • ConversionException
  • RestartRequestOnPageException
  • SQLException
  • UnAuthorisdeException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * Picon Framework
  5:  * http://code.google.com/p/picon-framework/
  6:  *
  7:  * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
  8: 
  9:  * Picon Framework is free software: you can redistribute it and/or modify
 10:  * it under the terms of the GNU General Public License as published by
 11:  * the Free Software Foundation, either version 3 of the License, or
 12:  * (at your option) any later version.
 13: 
 14:  * Picon Framework is distributed in the hope that it will be useful,
 15:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17:  *  General Public License for more details.
 18: 
 19:  * You should have received a copy of the GNU General Public License
 20:  * along with Picon Framework.  If not, see <http://www.gnu.org/licenses/>.
 21:  * */
 22: 
 23: namespace picon;
 24: 
 25: /**
 26:  * A component which may contain child components, allowing for a composition 
 27:  * hierarchy to be built
 28:  * 
 29:  * @author Martin Cassidy
 30:  * @package web
 31:  */
 32: class MarkupContainer extends Component
 33: {
 34:     private $children = array();
 35:     
 36:     public function add(&$object)
 37:     {
 38:         if($object instanceof Component)
 39:         {
 40:             $this->addComponent($object);
 41:             return;
 42:         }
 43:         parent::add($object);
 44:     }
 45:     
 46:     public function addOrReplace(Component &$component)
 47:     {
 48:         if($component->added)
 49:         {
 50:             throw new \RuntimeException(sprintf("Component %s has been added already.", $component->getId()));
 51:         }
 52:         if($this->childExists($component->getId()))
 53:         {
 54:             $old = &$this->children;
 55:             $old[$component->getId()] = $component;
 56:             $this->onComponentAdded($component);
 57:         }
 58:         else
 59:         {
 60:             $this->addComponent($component);
 61:         }
 62:     }
 63:     
 64:     protected final function remove(Component &$component)
 65:     {
 66:         if($this->childExists($component->getId()))
 67:         {
 68:             unset($this->children[$component->getId()]);
 69:         }
 70:     }
 71:     
 72:     protected final function addComponent(Component &$component)
 73:     {
 74:         if($this->childExists($component->getId()))
 75:         {
 76:             throw new \RuntimeException(sprintf("Component %s already has a child with id %s", $this->getId(), $component->getId()));
 77:         }
 78:         
 79:         if($component->added)
 80:         {
 81:             throw new \RuntimeException(sprintf("Component %s has already been added to another",$component->getId()));
 82:         }
 83:         
 84:         if($component==$this)
 85:         {
 86:             throw new \RuntimeException(sprintf("Component %s cannot be added to itself.",$component->getId()));
 87:         }
 88:         
 89:         $this->children[$component->getId()] = $component;
 90:         
 91:         $this->onComponentAdded($component);
 92:     }
 93:     
 94:     public function internalInitialize()
 95:     {
 96:         parent::internalInitialize();
 97:         $callback = function(&$component)
 98:         {
 99:             $component->internalInitialize();
100:             return Component::VISITOR_CONTINUE_TRAVERSAL;
101:         };
102:         $this->visitChildren(Component::getIdentifier(), $callback);
103:     }
104:     
105:     public function beforePageRender()
106:     {
107:         parent::beforePageRender();
108:         foreach($this->children as $child)
109:         {
110:             $child->beforePageRender();
111:         }
112:     }
113:     
114:     public function afterPageRender()
115:     {
116:         parent::afterPageRender();
117:         foreach($this->children as $child)
118:         {
119:             $child->afterPageRender();
120:         }
121:     }
122:     
123:     protected function onComponentAdded(Component &$component)
124:     {
125:         $component->setParent($this);
126:         $page = $this->getPage();
127:         
128:         if($page!=null)
129:         {
130:             if($page->isInitialized())
131:             {
132:                 $component->internalInitialize();
133:             }
134:         }
135:         
136:         if($this->isBeforePageRender())
137:         {
138:             $component->beforePageRender();
139:         }
140:     }
141:     
142:     public function getChildren()
143:     {
144:         return $this->children;
145:     }
146:     
147:     /**
148:      *
149:      * @param ComponentTag $tag 
150:      */
151:     protected function onComponentTagBody(ComponentTag $tag)
152:     {
153:         parent::onComponentTagBody($tag);
154:         if($tag->hasChildren())
155:         {
156:             $this->renderAll($tag->getChildren());
157:         }
158:     }
159:     
160:     public function get($id)
161:     {
162:         if(empty($id))
163:         {
164:             return $this;
165:         }
166:         if(substr($id, strlen($id)-1, strlen($id))!=self::PATH_SEPERATOR)
167:         {
168:             $id = $id.self::PATH_SEPERATOR;
169:         }
170:         $nodes = explode(self::PATH_SEPERATOR, $id);
171:         $child = $nodes[0];
172:         
173:         if($this->childExists($child))
174:         {
175:             $childComponent = $this->children[$child];
176:             return $childComponent->get(substr($id, strlen($child.self::PATH_SEPERATOR)));
177:         }
178:         return null;
179:     }
180:     
181:     protected function childExists($id)
182:     {
183:         return array_key_exists($id, $this->children);
184:     }
185:     
186:     public function hasChildren()
187:     {
188:         return count($this->children)>0;
189:     }
190:     
191:     /**
192:      * Recursivly visit all child components matching the Identifier and execute
193:      * a callback on each
194:      * @param Identifier $identifier
195:      * @param closure $callback 
196:      */
197:     public function visitChildren(Identifier $identifier, $callback)
198:     {
199:         Args::callBackArgs($callback, 1, 'callback');
200:         $this->internalVisitChildren($identifier, $this->getChildren(), $callback);
201:     }
202:     
203:     private function internalVisitChildren(Identifier $identifier, $components, $callback)
204:     {
205:         foreach($components as $component)
206:         {
207:             $response = self::VISITOR_CONTINUE_TRAVERSAL;
208:             if($component::getIdentifier()->of($identifier))
209:             {
210:                 $response = $callback($component);
211:             }
212:             if($response==self::VISITOR_CONTINUE_TRAVERSAL && $component instanceof MarkupContainer)
213:             {
214:                 $this->internalVisitChildren($identifier, $component->getChildren(), $callback);
215:             }
216:             else if($response==self::VISITOR_STOP_TRAVERSAL)
217:             {
218:                 break;
219:             }
220:         }
221:     }
222:     
223:     /**
224:      * Loads the markup accosiated with this markup container
225:      * @todo the functionality of this method should be extracted into
226:      * a helper class as it needs extending to load from parent folders
227:      */
228:     public function loadAssociatedMarkup()
229:     {
230:         return MarkupLoader::get()->loadMarkup($this);
231:     }
232:     
233:     protected function onRender()
234:     {
235:         $this->internalRenderComponent();
236:     }
237:     
238:     /**
239:      * Locates the ComponentTag for a particular Component
240:      * @param Component The child component to find the ComponentTag for
241:      */
242:     public function getMarkupForChild(Component $child)
243:     {
244:         return $this->getMarkUpSource()->getMarkup($this, $child);
245:     }
246:     
247:     public function detach()
248:     {
249:         foreach($this->getChildren() as $child)
250:         {
251:             if($child->isAuto())
252:             {
253:                 $this->remove($child);
254:             }
255:         }
256:     }
257: }
258: 
259: ?>
260: 
Picon Framework API documentation generated by ApiGen 2.7.0