Example #1
0
 /**
  * Constructor
  *
  * @param   object  An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the media url
     if (!$config->media_url instanceof HttpUrlInterface) {
         $this->_mediaurl = $this->getObject('lib:http.url', array('url' => $config->media_url));
     } else {
         $this->_mediaurl = $config->media_url;
     }
     //Set the auto assign state
     $this->_auto_assign = $config->auto_assign;
     //Set the data
     $this->_data = ObjectConfig::unbox($config->data);
     //Set the user-defined escaping callback
     $this->setEscape($config->escape);
     //Set the layout
     $this->setLayout($config->layout);
     //Set the template object
     $this->_template = $config->template;
     //Attach the template filters
     $filters = (array) ObjectConfig::unbox($config->template_filters);
     foreach ($filters as $key => $value) {
         if (is_numeric($key)) {
             $this->getTemplate()->attachFilter($value);
         } else {
             $this->getTemplate()->attachFilter($key, $value);
         }
     }
     //Add alias filter for media:// namespaced
     $this->getTemplate()->getFilter('alias')->addAlias(array('media://' => (string) $this->_mediaurl . '/'), TemplateFilter::MODE_COMPILE | TemplateFilter::MODE_RENDER);
 }
Example #2
0
 /**
  * Constructor.
  *
  * @param   ObjectConfig $config Configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     //Set the object manager
     if (isset($config->object_manager)) {
         $this->__object_manager = $config->object_manager;
     }
     //Set the object identifier
     if (isset($config->object_identifier)) {
         $this->__object_identifier = $config->object_identifier;
     }
     //Initialise the object
     $this->_initialize($config);
     //Add the mixins
     $mixins = (array) ObjectConfig::unbox($config->mixins);
     foreach ($mixins as $key => $value) {
         if (is_numeric($key)) {
             $this->mixin($value);
         } else {
             $this->mixin($key, $value);
         }
     }
     //Register the decorators
     $decorators = (array) ObjectConfig::unbox($config->decorators);
     foreach ($decorators as $key => $value) {
         if (is_numeric($key)) {
             $this->getIdentifier()->getDecorators()->append(array($value));
         } else {
             $this->getIdentifier()->getDecorators()->append(array($key, $value));
         }
     }
     //Set the object config
     $this->__object_config = $config;
 }
Example #3
0
 /**
  * Build a string with xml style attributes from  an array of key/value pairs
  *
  * @param   mixed   $array The array of Key/Value pairs for the attributes
  * @return  string  String containing xml style attributes
  */
 public function buildAttributes($array)
 {
     $output = array();
     if ($array instanceof ObjectConfig) {
         $array = ObjectConfig::unbox($array);
     }
     if (is_array($array)) {
         foreach ($array as $key => $item) {
             if (is_array($item)) {
                 if (empty($item)) {
                     continue;
                 }
                 $item = implode(' ', $item);
             }
             if (is_bool($item)) {
                 if ($item === false) {
                     continue;
                 }
                 $item = $key;
             }
             $output[] = $key . '="' . str_replace('"', '"', $item) . '"';
         }
     }
     return implode(' ', $output);
 }
Example #4
0
 /**
  * Constructor
  *
  * @param ObjectConfig  $config  A ObjectConfig object with optional configuration options
  * @return Object
  */
 public function __construct(ObjectConfig $config)
 {
     //Set the object manager
     if (!$config->object_manager instanceof ObjectManagerInterface) {
         throw new \InvalidArgumentException('object_manager [ObjectManagerInterface] config option is required, "' . gettype($config->object_manager) . '" given.');
     } else {
         $this->__object_manager = $config->object_manager;
     }
     //Set the object identifier
     if (!$config->object_identifier instanceof ObjectIdentifierInterface) {
         throw new \InvalidArgumentException('object_identifier [ObjectIdentifierInterface] config option is required, "' . gettype($config->object_identifier) . '" given.');
     } else {
         $this->__object_identifier = $config->object_identifier;
     }
     //Initialise the object
     $this->_initialize($config);
     //Set the object config
     $this->__object_config = $config;
     //Add the mixins
     $mixins = (array) ObjectConfig::unbox($config->mixins);
     foreach ($mixins as $key => $value) {
         if (is_numeric($key)) {
             $this->mixin($value);
         } else {
             $this->mixin($key, $value);
         }
     }
 }
Example #5
0
 /**
  * Invoke a template helper
  *
  * This function accepts a partial identifier, in the form of helper.method or schema:package.helper.method. If
  * a partial identifier is passed a full identifier will be created using the template identifier.
  *
  * If the state have the same string keys, then the parameter value for that key will overwrite the state.
  *
  * @param    string   $identifier Name of the helper, dot separated including the helper function to call
  * @param    array    $params     An optional associative array of functions parameters to be passed to the helper
  * @return   string   Helper output
  * @throws   \BadMethodCallException If the helper function cannot be called.
  */
 public function invokeHelper($identifier, $params = array())
 {
     //Get the function and helper based on the identifier
     $parts = explode('.', $identifier);
     $function = array_pop($parts);
     $identifier = array_pop($parts);
     //Handle schema:package.helper.function identifiers
     if (!empty($parts)) {
         $identifier = implode('.', $parts) . '.template.helper.' . $identifier;
     }
     //Create the complete identifier if a partial identifier was passed
     if (is_string($identifier) && strpos($identifier, '.') === false) {
         $helper = $this->getMixer()->getIdentifier()->toArray();
         if ($helper['type'] != 'lib') {
             $helper['path'] = array('template', 'helper');
         } else {
             $helper['path'] = array('helper');
         }
         $helper['name'] = $identifier;
     } else {
         $helper = $this->getIdentifier($identifier);
     }
     $helper = $this->getObject('template.helper.factory')->createHelper($helper, ObjectConfig::unbox($params));
     //Call the helper function
     if (!is_callable(array($helper, $function))) {
         throw new \BadMethodCallException(get_class($helper) . '::' . $function . ' not supported.');
     }
     //Merge the parameters if helper asks for it
     if ($helper instanceof TemplateHelperParameterizable) {
         $params = array_merge($this->getParameters()->toArray(), $params);
     }
     return $helper->{$function}($params);
 }
 /**
  * Constructor
  *
  * @param ObjectConfig|null $config  An optional ObjectConfig object with configuration options
  * @return UserSession
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Session write and close handlers are called after destructing objects since PHP 5.0.5.
     if (version_compare(phpversion(), '5.4.0', '>=')) {
         session_register_shutdown();
     } else {
         register_shutdown_function('session_write_close');
     }
     //Set the session options
     $this->setOptions($config->options);
     //Set the session name
     if (!empty($config->name)) {
         $this->setName($config->name);
     }
     //Set the session identifier
     if (!empty($config->id)) {
         $this->setId($config->id);
     }
     //Set the session namespace
     $this->setNamespace($config->namespace);
     //Set lifetime time
     $this->getContainer('metadata')->setLifetime($config->lifetime);
     //Set the session handler
     $this->setHandler($config->handler, ObjectConfig::unbox($config));
 }
Example #7
0
 /**
  * Object constructor
  *
  * @param   ObjectConfig $config Configuration options
  * @throws \InvalidArgumentException
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     if (is_null($config->command_chain)) {
         throw new \InvalidArgumentException('command_chain [CommandChainInterface] config option is required');
     }
     //Create a command chain object
     $this->__command_chain = $config->command_chain;
     //Set the command priority
     $this->_priority = $config->priority;
     //Add the event subscribers
     $handlers = (array) ObjectConfig::unbox($config->command_handlers);
     foreach ($handlers as $key => $value) {
         if (is_numeric($key)) {
             $this->addCommandHandler($value);
         } else {
             $this->addCommandHandler($key, $value);
         }
     }
     //Add the command callbacks
     foreach ($this->getMixer()->getMethods() as $method) {
         $match = array();
         if (preg_match('/_(after|before)([A-Z]\\S*)/', $method, $match)) {
             $this->addCommandCallback($match[1] . '.' . strtolower($match[2]), $method);
         }
     }
 }
Example #8
0
 /**
  * Return the views output
  *
  * @param ViewContextTemplate  $context A view context object
  * @return string  The output of the view
  */
 protected function _actionRender(ViewContextTemplate $context)
 {
     $data = ObjectConfig::unbox($context->data);
     $path = $this->qualifyLayout($context->layout);
     //Render the template
     $content = $this->getTemplate()->setParameters($context->parameters)->render($path, $data);
     return $content;
 }
 /**
  * Constructor
  *
  * @param ObjectConfig $config  An optional ObjectConfig object with configuration options
  * @return ObjectArray
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     $parameters = ObjectConfig::unbox($config->parameters);
     foreach ($parameters as $key => $values) {
         $this->set($key, $values);
     }
 }
Example #10
0
 /**
  * Constructor.
  *
  * @param   ObjectConfig $config Configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     $schemes = ObjectConfig::unbox($config->schemes);
     foreach (array_reverse($schemes) as $alias => $path) {
         $this->addScheme($alias, $path);
     }
 }
Example #11
0
 /**
  * Constructor.
  *
  * @param   ObjectConfig $config Configuration options
  */
 public function __construct(ObjectConfig $config = null)
 {
     parent::__construct($config);
     $this->_columns = (array) ObjectConfig::unbox($config->columns);
     $this->_separator = $config->separator;
     $this->_updatable = $config->updatable;
     $this->_length = $config->length;
     $this->_unique = $config->unique;
 }
Example #12
0
 /**
  * Recalculate offset
  *
  * @param   ModelContextInterface $context A model context object
  * @return    void
  */
 protected function _afterReset(ModelContextInterface $context)
 {
     $modified = (array) ObjectConfig::unbox($context->modified);
     if (in_array('limit', $modified)) {
         $limit = $context->state->limit;
         if ($limit) {
             $context->state->offset = floor($context->state->offset / $limit) * $limit;
         }
     }
 }
Example #13
0
 /**
  * Constructor
  *
  * Prevent creating instances of this class by making the constructor private
  *
  * @param ObjectConfig $config   An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Reset the data
     $this->__data = array();
     //Register the functions
     $functions = ObjectConfig::unbox($config->functions);
     foreach ($functions as $name => $callback) {
         $this->registerFunction($name, $callback);
     }
 }
Example #14
0
 /**
  * Registers all natively provided mime type resolvers.
  *
  * @param ObjectConfig $config An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Register the resolvers
     $resolvers = ObjectConfig::unbox($config->resolvers);
     foreach ($resolvers as $key => $value) {
         if (is_numeric($key)) {
             $this->registerResolver($value);
         } else {
             $this->registerResolver($key, $value);
         }
     }
 }
Example #15
0
 /**
  * Constructor
  *
  * @param ObjectConfig $config  An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Add the toolbars
     $toolbars = (array) ObjectConfig::unbox($config->toolbars);
     foreach ($toolbars as $key => $value) {
         if (is_numeric($key)) {
             $this->attachToolbar($value);
         } else {
             $this->attachToolbar($key, $value);
         }
     }
 }
Example #16
0
 /**
  * Constructor
  *
  * @param ObjectConfig $config An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Add the behaviors in FIFO order
     $behaviors = (array) ObjectConfig::unbox($config->behaviors);
     foreach ($behaviors as $key => $value) {
         if (is_numeric($key)) {
             $this->addBehavior($value);
         } else {
             $this->addBehavior($key, $value);
         }
     }
 }
Example #17
0
 /**
  * Generates a select option list
  *
  * @param 	array 	$config An optional array with configuration options
  * @return	array	An array of objects containing the option attributes
  */
 public function options($config = array())
 {
     $config = new ObjectConfig($config);
     $config->append(array('entity' => array(), 'name' => 'id', 'value' => 'id', 'label' => 'id', 'disabled' => null, 'attribs' => array()));
     $options = array();
     foreach ($config->entity as $entity) {
         $option = array('id' => isset($entity->{$config->name}) ? $entity->{$config->name} : null, 'name' => $config->name, 'disabled' => $config->disabled, 'attribs' => ObjectConfig::unbox($config->attribs), 'value' => $entity->{$config->value}, 'label' => $entity->{$config->label});
         if ($config->entity instanceof \RecursiveIteratorIterator) {
             $option['level'] = $config->entity->getDepth() + 1;
         }
         $options[] = $this->option($option);
     }
     return $options;
 }
Example #18
0
 public function script($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('strings' => array()));
     $strings = ObjectConfig::unbox($config->strings);
     $translator = $this->getObject('translator');
     $translations = array();
     foreach ($strings as $string) {
         $translations[$string] = $translator->translate($string);
     }
     $html = '';
     $html .= $this->createHelper('behavior')->kodekit() . "<script>\n            if (typeof Kodekit === 'object' && Kodekit !== null) {\n                if (typeof Kodekit.translator === 'object' && Kodekit.translator !== null) {\n                    Kodekit.translator.loadTranslations(" . json_encode($translations) . ");\n                }\n            }\n            </script>\n            ";
     return $html;
 }
Example #19
0
 /**
  * Constructor.
  *
  * @param ObjectConfig $config	An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the filters
     $this->__authenticator_queue = $this->getObject('lib:object.queue');
     //Add the authenticators
     $authenticators = (array) ObjectConfig::unbox($config->authenticators);
     foreach ($authenticators as $key => $value) {
         if (is_numeric($key)) {
             $this->addAuthenticator($value);
         } else {
             $this->addAuthenticator($key, $value);
         }
     }
 }
Example #20
0
 /**
  * Constructor
  *
  * @param ObjectConfig $object An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the auto mixin state
     $this->_auto_mixin = $config->auto_mixin;
     //Add the behaviors
     $behaviors = (array) ObjectConfig::unbox($config->behaviors);
     foreach ($behaviors as $key => $value) {
         if (is_numeric($key)) {
             $this->attachBehavior($value);
         } else {
             $this->attachBehavior($key, $value);
         }
     }
 }
Example #21
0
 /**
  * Constructor.
  *
  * @param ObjectConfig $config	An optional ObjectConfig object with configuration options.
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Create the transport queue
     $this->_queue = $this->getObject('lib:object.queue');
     //Attach the response transport handlers
     $transports = (array) ObjectConfig::unbox($config->transports);
     foreach ($transports as $key => $value) {
         if (is_numeric($key)) {
             $this->attachTransport($value);
         } else {
             $this->attachTransport($key, $value);
         }
     }
 }
Example #22
0
 /**
  * Constructor
  *
  * @param   ObjectConfig $config Configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the data
     $this->__data = ObjectConfig::unbox($config->data);
     //Set the parameters
     $this->__parameters = ObjectConfig::unbox($config->parameters);
     $this->setUrl($config->url);
     $this->setTitle($config->title);
     $this->setContent($config->content);
     $this->setMimetype($config->mimetype);
     $this->setModel($config->model);
     // Mixin the behavior (and command) interface
     $this->mixin('lib:behavior.mixin', $config);
 }
Example #23
0
 /**
  * Constructor.
  *
  * @param ObjectConfig $config Configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set debug
     $this->setDebug($config->debug);
     //Set cache
     $this->setCache($config->cache, $config->cache_path, $config->cache_reload);
     //Register the engines
     $engines = ObjectConfig::unbox($config->engines);
     foreach ($engines as $key => $value) {
         if (is_numeric($key)) {
             $this->registerEngine($value);
         } else {
             $this->registerEngine($key, $value);
         }
     }
 }
Example #24
0
 /**
  * Constructor
  *
  * @param   ObjectConfig $config Configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     $this->_version = $config->version;
     $this->_text_fields = ObjectConfig::unbox($config->text_fields);
     $this->_fields = ObjectConfig::unbox($config->fields);
     $query = $this->getUrl()->getQuery(true);
     if (!empty($query['fields']) && is_array($query['fields'])) {
         foreach ($query['fields'] as $type => $list) {
             if (!isset($this->_fields[$type])) {
                 $this->_fields[$type] = array();
             }
             $this->_fields[$type] = explode(',', rawurldecode($list));
         }
     }
     $this->addCommandCallback('before.render', '_convertRelativeLinks');
 }
Example #25
0
 /**
  * Add the toolbars to the controller
  *
  * @param ControllerContext $context
  * @return void
  */
 protected function _beforeRender(ControllerContext $context)
 {
     $controller = $context->getSubject();
     // Add toolbars on authenticated requests only.
     if ($controller->getUser()->isAuthentic()) {
         //Add the toolbars
         $toolbars = (array) ObjectConfig::unbox($this->getConfig()->toolbars);
         foreach ($toolbars as $key => $value) {
             if (is_numeric($key)) {
                 $this->addToolbar($value);
             } else {
                 $this->addToolbar($key, $value);
             }
         }
     }
     //Add the template filter and inject the toolbars
     if ($controller->getView() instanceof ViewTemplatable) {
         $controller->getView()->getTemplate()->addFilter('toolbar', array('toolbars' => $this->getToolbars()));
     }
 }
Example #26
0
 /**
  * Register a named callback
  *
  * If the callback has already been registered. It will not be re-registered.
  *
  * @param  	string      	$name       The callback name to register the callback for
  * @param 	callable		$callback   The callback function to register
  * @param   array|object    An associative array of config parameters or a KConfig object
  * @throws  \InvalidArgumentException If the callback is not a callable
  * @return  Object	The mixer object
  */
 public function registerCallback($name, $callback, $params = array())
 {
     if (!is_callable($callback)) {
         throw new \InvalidArgumentException('The callback must be a callable, "' . gettype($callback) . '" given.');
     }
     $params = (array) ObjectConfig::unbox($params);
     $name = strtolower($name);
     if (!isset($this->_callbacks[$name])) {
         $this->_callbacks[$name] = array();
         $this->_params[$name] = array();
     }
     //Don't re-register names
     $index = array_search($callback, $this->_callbacks[$name], true);
     if ($index === false) {
         $this->_callbacks[$name][] = $callback;
         $this->_params[$name][] = $params;
     } else {
         $this->_params[$name][$index] = array_merge($this->_params[$name][$index], $params);
     }
     return $this->getMixer();
 }
Example #27
0
 /**
  * Constructor
  *
  * @param   object  An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the auto assign state
     $this->_auto_assign = $config->auto_assign;
     //Set the data
     $this->_data = ObjectConfig::unbox($config->data);
     //Set the layout
     $this->setLayout($config->layout);
     //Set the template object
     $this->_template = $config->template;
     //Attach the template filters
     $filters = (array) ObjectConfig::unbox($config->template_filters);
     foreach ($filters as $key => $value) {
         if (is_numeric($key)) {
             $this->getTemplate()->attachFilter($value);
         } else {
             $this->getTemplate()->attachFilter($key, $value);
         }
     }
 }
Example #28
0
 /**
  * Constructor
  *
  * Prevent creating instances of this class by making the constructor private
  *
  * @param ObjectConfig $config   An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     // Set the view identifier
     $this->_view = $config->view;
     // Set the template data
     $this->_data = $config->data;
     //Set the filter chain
     $this->_chain = $config->filter_chain;
     //Attach the filters
     $filters = (array) ObjectConfig::unbox($config->filters);
     foreach ($filters as $key => $value) {
         if (is_numeric($key)) {
             $this->attachFilter($value);
         } else {
             $this->attachFilter($key, $value);
         }
     }
     //Reset the counter
     $this->_stack = array();
 }
Example #29
0
 /**
  * Constructor.
  *
  * @param ObjectConfig $config An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     $this->_bootstrapped = false;
     //Force a reload if cache is enabled and we have already bootstrapped
     if ($config->force_reload && $config->bootstrapped) {
         $config->bootstrapped = false;
         $config->directories = array();
         $config->components = array();
         $config->namespaces = array();
         $config->files = array();
         $config->aliases = array();
         $config->identifiers = array();
     }
     $this->_directories = ObjectConfig::unbox($config->directories);
     $this->_components = ObjectConfig::unbox($config->components);
     $this->_namespaces = ObjectConfig::unbox($config->namespaces);
     $this->_files = ObjectConfig::unbox($config->files);
     $this->_aliases = ObjectConfig::unbox($config->aliases);
     $this->_identifiers = ObjectConfig::unbox($config->identifiers);
 }
Example #30
0
 /**
  * Object constructor
  *
  * @param ObjectConfig $config  An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     if (is_null($config->event_dispatcher)) {
         throw new \InvalidArgumentException('event_dispatcher [EventDispatcherInterface] config option is required');
     }
     //Set the event dispatcher
     $this->_event_dispatcher = $config->event_dispatcher;
     //Add the event listeners
     foreach ($config->event_listeners as $event => $listener) {
         $this->addEventListener($event, $listener);
     }
     //Add the event handlers
     $subscribers = (array) ObjectConfig::unbox($config->event_subscribers);
     foreach ($subscribers as $key => $value) {
         if (is_numeric($key)) {
             $this->addEventSubscriber($value);
         } else {
             $this->addEventSubscriber($key, $value);
         }
     }
 }