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:  * Holder for the map to all statfull and statless web pages
 27:  *
 28:  * A singleton which will persist from one request to another via the session
 29:  * For this reason it is important that all stored objects are serializable
 30:  *
 31:  * The page map stores a map of all stateless pages by both their direct path
 32:  * (the name of the class, including its namespace) and also all specified
 33:  * paths (pages which have been given @Path) Pagges are expected to extend 
 34:  * WebPage @see WebPage
 35:  * 
 36:  * Additionally, actual instances of pages which have deemed statfull are stored
 37:  * against an associated page id.
 38:  *
 39:  * @author Martin Cassidy
 40:  * @package web
 41:  */
 42: class PageMap
 43: {
 44:     const PAGE_MAP_RESOURCE_NAME = 'pagemap';
 45:     const PAGE_MAP_MOUNTED_RESOURCE_NAME ='map_mounted';
 46:     private $pages;
 47:     private $pageId = 1;
 48:     private $pageInstances = array();
 49:     private static $self;
 50:     private $mountedPages;
 51: 
 52:     /**
 53:      * Private constructor, this is a singleton
 54:      * Loads in ALL .php files from the assets directory
 55:      * Builds the page map array
 56:      */
 57:     private function __construct()
 58:     {
 59:         //singleton
 60:     }
 61: 
 62:     public function initialise()
 63:     {
 64:         if(isset($this->pages) && $this->pages!=null)
 65:         {
 66:             return;
 67:         }
 68:         $this->mountedPages = array();
 69:         $this->scanPages();
 70:     }
 71: 
 72:     private function scanPages()
 73:     {
 74:         ApplicationInitializer::loadAssets(ASSETS_DIRECTORY);
 75:         $this->pages = array();
 76:         $scanner = new ClassScanner(array(new SubClassRule('\picon\WebPage')));
 77: 
 78:         $pages = $scanner->scanForName();
 79:         foreach($pages as $pageName)
 80:         {
 81:             $this->addToPath($pageName, $pageName);
 82:         }
 83: 
 84:         $pathScanner = new ClassScanner(array(new AnnotationRule('Path')));
 85: 
 86:         foreach($pathScanner->scanForReflection($pages) as $reflection)
 87:         {
 88:             $pathAnnoation = $reflection->getAnnotation('Path');
 89:             $path = $pathAnnoation->path;
 90: 
 91:             if(empty($path))
 92:             {
 93:                 throw new \UnexpectedValueException(sprintf("Expecting path annoation to have a path value for class %s", $reflection->getName()));
 94:             }
 95: 
 96:             $this->addToPath($path, $reflection->getNamespaceName().'\\'.$reflection->getName());
 97:         }
 98:         PiconApplication::get()->getPageMapInitializationListener()->onInitialize($this);
 99:     }
100: 
101:     private function addToPath($path, $pageName)
102:     {
103:         if(array_key_exists($path, $this->pages))
104:         {
105:             throw new \DuplicatePageDefinitionException(sprintf("A page with path %s already exists and cannot be used again.", $path));
106:         }
107:         $this->pages[$path] = $pageName;
108:     }
109: 
110:     /**
111:      * Gets the array containing the page map
112:      * If this is the first invoke for this method, the page map will
113:      * be generated
114:      * @return Array The page map
115:      */
116:     public static function getPageMap()
117:     {
118:         return self::get()->pages;
119:     }
120:     
121:     public static function getNextPageId()
122:     {
123:         $self = self::get();
124:         $self->pageId++;
125:         return 'page'.$self->pageId;
126:     }
127:     
128:     public function getPageById($id)
129:     {
130:         if(array_key_exists($id, $this->pageInstances))
131:         {
132:             return $this->pageInstances[$id];
133:         }
134: 
135:         $page = CacheManager::loadResource($id, CacheManager::SESSION_SCOPE);
136: 
137:         if($page!=null)
138:         {
139:             $this->addOrUpdate($page);
140:             return $page;
141:         }
142:         else
143:         {
144:             return null;
145:         }
146:     }
147: 
148:     public static function get()
149:     {
150:         if (!isset(self::$self))
151:         {
152:             if (isset($_SESSION['page_map']))
153:             {
154:                 self::$self = unserialize($_SESSION['page_map']); 
155:             }
156:             else
157:             {
158:                 self::$self = new self();
159:             }
160:         }
161:         return self::$self;
162:     }
163:     
164:     public function addOrUpdate(WebPage &$page)
165:     {
166:         $instances = &$this->pageInstances;
167:         $instances[$page->getId()] = $page;
168:     }
169:     
170:     public function __sleep()
171:     {
172:         CacheManager::saveResource(self::PAGE_MAP_RESOURCE_NAME, $this->pages, CacheManager::APPLICATION_SCOPE);
173:         CacheManager::saveResource(self::PAGE_MAP_MOUNTED_RESOURCE_NAME, $this->mountedPages, CacheManager::APPLICATION_SCOPE);
174:         return array('pageId');
175:     }
176:     
177:     public function __wakeup()
178:     {
179:         $this->pages = CacheManager::loadResource(self::PAGE_MAP_RESOURCE_NAME, CacheManager::APPLICATION_SCOPE);
180:         $this->mountedPages = CacheManager::loadResource(self::PAGE_MAP_MOUNTED_RESOURCE_NAME, CacheManager::APPLICATION_SCOPE);
181:     }
182:     
183:     public function __destruct()
184:     {
185:         foreach($this->pageInstances as $pageid => $page)
186:         {
187:             CacheManager::saveResource($pageid, $page, CacheManager::SESSION_SCOPE);
188:         }
189:         $_SESSION['page_map'] = serialize($this);
190:     }
191:     
192:     public function mount($path, Identifier $page)
193:     {
194:         if(!$page->of(WebPage::getIdentifier()))
195:         {
196:             throw new \InvalidArgumentException('Expected an identifier of a web page');
197:         }
198:         if($this->isMounted($path))
199:         {
200:             throw new \InvalidArgumentException(sprintf('The path %s is already mounted', $path));
201:         }
202:         $this->addToPath($path, $page->getFullyQualifiedName());
203:         $this->mountedPages[] = $path;
204:     }
205:     
206:     public function isMounted($path)
207:     {
208:         return in_array($path, $this->mountedPages);
209:     }
210:     
211:     public function unMount($path)
212:     {
213:         if($this->isMounted($path))
214:         {
215:             unset($this->pages[$path]);
216:             $key = array_search($path, $this->mountedPages);
217:             unset($this->mountedPages[$key]);
218:         }
219:     }
220:     
221:     public function getMounted()
222:     {
223:         return $this->mountedPages;
224:     }
225: }
226: 
227: ?>
228: 
Picon Framework API documentation generated by ApiGen 2.7.0