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:  * Helper class for saving and loading resources from the cache.
 27:  * 
 28:  * This can work for both the application and session scope allowing resources
 29:  * to be shared accross sessions
 30:  *
 31:  * @author Martin Cassidy
 32:  */
 33: class CacheManager
 34: {
 35:     const EXTENSION = '.pcx';
 36:     const SESSION_PATH = 'session_data';
 37:     const APPLICATION_PATH = 'application_data';
 38:     
 39:     const APPLICATION_SCOPE = '1';
 40:     const SESSION_SCOPE = '2';
 41:     
 42:     private static $self;
 43:     
 44:     private function __construct()
 45:     {
 46:         //singleton
 47:     }
 48:     
 49:     /**
 50:      * Saves a resource to the cache.
 51:      * @param type $name
 52:      * @param type $resource
 53:      * @param type $scope 
 54:      */
 55:     public static function saveResource($name, $resource, $scope)
 56:     {
 57:         Args::isString($name, 'name');
 58:         $instance = self::get();
 59:         $dir = $instance->getDirectoryForScope($scope);
 60:         $instance->internalSaveResource($dir, $name, $resource);
 61:     }
 62:     
 63:     /**
 64:      * Load a previously saved resource. If the resource was not
 65:      * found this will return null
 66:      * @param type $name
 67:      * @param type $scope
 68:      * @return type 
 69:      */
 70:     public static function loadResource($name, $scope)
 71:     {
 72:         $instance = self::get();
 73:         $directory = $instance->getDirectoryForScope($scope);
 74:         return $instance->internalLoadResource($directory, $name);
 75:     }
 76:     
 77:     private static function get()
 78:     {
 79:         if(!isset(self::$self))
 80:         {
 81:             self::$self = new self();
 82:         }
 83:         return self::$self;
 84:     }
 85:     
 86:     private function getDirectoryForScope($scope)
 87:     {
 88:         $dir = null;
 89:         if($scope==self::SESSION_SCOPE)
 90:         {
 91:             $dir = self::get()->getSessionCacheDirectory();
 92:         }
 93:         else if($scope==self::APPLICATION_SCOPE)
 94:         {
 95:             $dir = self::get()->getApplicationCacheDirectory();
 96:         }
 97:         else
 98:         {
 99:             throw new \InvalidArgumentException('Invalid scope argument for saveResource()');
100:         }
101:         return $dir;
102:     }
103:     
104:     private function getSessionCacheDirectory()
105:     {
106:         return CACHE_DIRECTORY.'/'.self::SESSION_PATH.'/'.session_id().'/';
107:     }
108:     
109:     private function getApplicationCacheDirectory()
110:     {
111:         return CACHE_DIRECTORY.'/'.self::APPLICATION_PATH.'/';
112:     }
113:     
114:     private function getFileName($directory, $name)
115:     {
116:         return $directory.$this->sanitizeFileName($name).self::EXTENSION;
117:     }
118:     
119:     private function internalSaveResource($directory, $name, $resource)
120:     {
121:         $fileName = $this->getFileName($directory, $name);
122:         
123:         if(!file_exists($directory))
124:         {
125:             mkdir($directory, 0755, true);
126:         }
127:         
128:         file_put_contents($fileName, PiconSerializer::serialize($resource));
129:     }
130:     
131:     private function internalLoadResource($directory, $name)
132:     {
133:         $fileName = $this->getFileName($directory, $name);
134:         
135:         if(file_exists($fileName))
136:         {
137:             $contents = file_get_contents($fileName);
138:             return PiconSerializer::unserialize($contents);
139:         }
140:         else
141:         {
142:             return null;
143:         }
144:     }
145:     
146:     /**
147:      * Determins whether a resource with that name exists
148:      * @param type $name
149:      * @param type $scope
150:      * @return type 
151:      */
152:     public static function resourceExists($name, $scope)
153:     {
154:         $dir = self::get()->getDirectoryForScope($scope);
155:         $fileName = self::get()->getFileName($dir, $name);
156:         
157:         return file_exists($fileName);
158:     }
159:     
160:     private function sanitizeFileName($fileName)
161:     {
162:         return str_replace(':', '_', $fileName);
163:     }
164: }
165: 
166: ?>
167: 
Picon Framework API documentation generated by ApiGen 2.7.0