/**
  * Gets the export view for the provided extension
  * @param string $extension
  * @return ExportView
  */
 public function getExportView($extension)
 {
     if (!array_key_exists($extension, $this->extensions)) {
         throw new ZiboException($extension . ' is not a registered export extension');
     }
     $objectFactory = new ObjectFactory();
     return $objectFactory->create($this->extensions[$extension], self::INTERFACE_EXPORT_VIEW);
 }
 public function testCreateNonExistingClassThrowsException()
 {
     try {
         $this->factory->create('nonExistingClass');
         $this->fail('Exception expected for creating instance of non existing class');
     } catch (ZiboException $e) {
     }
 }
 /**
  * Constructs a new model manager
  * @return null
  */
 private function __construct()
 {
     $this->models = array();
     $objectFactory = new ObjectFactory();
     $modelIO = $objectFactory->createFromConfig(self::CONFIG_MODEL_IO, self::DEFAULT_MODEL_IO, self::INTERFACE_MODEL_IO);
     $modelReader = new ModelReader($modelIO);
     $this->modelLoader = new ModelLoader($modelReader);
     $this->modelCache = $objectFactory->createFromConfig(self::CONFIG_MODEL_CACHE, self::DEFAULT_MODEL_CACHE, self::INTERFACE_MODEL_CACHE);
 }
 /**
  * Creates a model
  * @param zibo\library\orm\definition\ModelTable $table Table definition of the model
  * @param string $modelClassName Class name for the model
  * @param string $dataClassName Class name for the data objects of the model
  * @return zibo\library\orm\model\Model
  * @throws
  */
 public function createModel(ModelTable $table, $modelClassName = null, $dataClassName = null)
 {
     if (is_null($modelClassName)) {
         $modelClassName = ModelManager::DEFAULT_MODEL;
     } elseif (String::isEmpty($modelClassName)) {
         throw new ModelException('Provided class name for the model is empty');
     }
     $modelMeta = new ModelMeta($table, $dataClassName);
     $objectFactory = new ObjectFactory();
     return $objectFactory->create($modelClassName, ModelManager::INTERFACE_MODEL, array($modelMeta));
 }
 /**
  * Creates an instance of the provided dependency
  * @param string $interface Full class name of the interface or parent class
  * @param Dependency $dependency Definition of the class to create
  * @param array $exclude Array with the interface as key and an array with
  * id's of dependencies as key to exclude from the get calls.
  * @return mixed Instance of the dependency
  * @throws zibo\ZiboException when the dependency could not be created
  */
 protected function create($interface, Dependency $dependency, array $exclude = null)
 {
     if (!self::$objectFactory) {
         self::$objectFactory = new ObjectFactory();
     }
     if (!$exclude) {
         $exclude = array($interface => array($dependency->getId() => true));
     } elseif (!isset($exclude[$interface])) {
         $exclude[$interface] = array($dependency->getId() => true);
     } else {
         $exclude[$interface][$dependency->getId()] = true;
     }
     $className = $dependency->getClassName();
     $arguments = $dependency->getConstructorArguments();
     $arguments = $this->getCallbackArguments($arguments, $exclude);
     $instance = self::$objectFactory->create($className, $interface, $arguments);
     $calls = $dependency->getCalls();
     if ($calls) {
         foreach ($calls as $call) {
             $arguments = $this->getCallbackArguments($call->getArguments(), $exclude);
             $callback = new Callback(array($instance, $call->getMethodName()));
             $callback->invokeWithArrayArguments($arguments);
         }
     }
     return $instance;
 }
 /**
  * Loads the profiles from the Zibo configuration.
  * @return array Array with Profile instances
  */
 public function loadProfiles()
 {
     $profiles = array();
     $configProfiles = Zibo::getInstance()->getConfigValue(self::CONFIG_PROFILES);
     if (!$configProfiles) {
         return $profiles;
     }
     if (!is_array($configProfiles)) {
         $configProfiles = array($configProfiles);
     }
     $objectFactory = new ObjectFactory();
     foreach ($configProfiles as $name => $profileClassName) {
         $profile = $objectFactory->create($profileClassName, self::INTERFACE_PROFILE);
         $profiles[$name] = $profile;
     }
     return $profiles;
 }
 /**
  * Loads the defined modules from the Zibo Configuration
  * @param zibo\core\Zibo $zibo Instance of Zibo
  * @return array Array with the defined modules
  * @throws zibo\ZiboException when a module could not be created
  * @see Module
  * @see CONFIG_MODULE
  */
 public function loadModules(Zibo $zibo)
 {
     $configModules = $zibo->getConfigValue(self::CONFIG_MODULE);
     if (!$configModules) {
         return array();
     }
     $objectFactory = new ObjectFactory();
     $modules = array();
     $configModules = Config::parseConfigTree($configModules);
     foreach ($configModules as $configKey => $moduleClass) {
         try {
             $modules[] = $objectFactory->create($moduleClass, self::INTERFACE_MODULE);
         } catch (ZiboException $exception) {
             throw new ZiboException('Could not create ' . $moduleClass . ' from the ' . $configKey . ' configuration key', 0, $exception);
         }
     }
     return $modules;
 }
 /**
  * Gets the controller of a request. If the controller class name is the same as the clasa name
  * of the controller which is set through setController, the set controller will be used instead
  * of creating a new one.
  * @param Request $request
  * @return Controller
  * @throws zibo\ZiboException when no object factory has been set
  * @throws zibo\ZiboException when the controller could not be created
  */
 protected function getController(Request $request)
 {
     try {
         $controller = $this->objectFactory->create($request->getControllerName(), self::INTERFACE_CONTROLLER);
     } catch (ZiboException $exception) {
         throw new ZiboException('Could not create controller ' . $request->getControllerName(), 0, $exception);
     }
     return $controller;
 }
 /**
  * Loads the modifiers from the Zibo configuration
  * @return null
  */
 private function loadModifiers()
 {
     $this->modifiers = array();
     $objectFactory = new ObjectFactory();
     $modifiers = Zibo::getInstance()->getConfigValue(self::CONFIG_MODIFIERS);
     foreach ($modifiers as $name => $className) {
         $this->modifiers[$name] = $objectFactory->create($className, self::INTERFACE_MODIFIER);
     }
 }
 /**
  * Loads a set of requirements from the Zibo configuration. The checks of the requirements are also invoked
  * @param string $configKey The configuration key for the requirement set
  * @return array Array with Requirement instances
  */
 public function loadRequirements($configKey)
 {
     $requirements = array();
     $configRequirements = Zibo::getInstance()->getConfigValue($configKey);
     if (!$configRequirements) {
         return $requirements;
     }
     if (!is_array($configRequirements)) {
         $configRequirements = array($configRequirements);
     }
     $objectFactory = new ObjectFactory();
     foreach ($configRequirements as $requirementClassName) {
         $requirement = $objectFactory->create($requirementClassName, self::INTERFACE_REQUIREMENT);
         $requirement->performCheck();
         $requirements[] = $requirement;
     }
     return $requirements;
 }
 /**
  * Gets all the available widgets
  * @return array Array with the namespace as key and an array as value. The array as value has
  *               the name of the widget as key and an instance of the widget as value
  */
 public function getWidgets()
 {
     $widgets = array();
     foreach ($this->widgets as $namespace => $widgetClasses) {
         $widgets[$namespace] = array();
         foreach ($widgetClasses as $name => $widgetClass) {
             $widgets[$namespace][$name] = $this->objectFactory->create($widgetClass, self::INTERFACE_WIDGET);
         }
     }
     return $this->orderWidgets($widgets);
 }
 /**
  * Create a data container for the model
  * @param zibo\library\orm\model\meta\ModelMeta $meta the meta of the model
  * @param zibo\library\ObjectFactory $objectFactory factory for new objects
  * @param boolean $initialize set to true to get an object with default values, false to get an empty object
  * @return mixed a data container for the model
  */
 private function initData(ModelMeta $meta, ObjectFactory $objectFactory, $initialize)
 {
     $data = $objectFactory->create($meta->getDataClassName());
     if (!$initialize) {
         return $data;
     }
     $fields = $meta->getFields();
     foreach ($fields as $field) {
         $name = $field->getName();
         if ($field instanceof BelongsToField || $field instanceof HasOneField) {
             $data->{$name} = null;
             continue;
         }
         if ($field instanceof HasManyField) {
             $data->{$name} = array();
             continue;
         }
         $data->{$name} = $field->getDefaultValue();
     }
     return $data;
 }
 /**
  * Gets the controller of a request. If the controller class name is the same as the clasa name
  * of the controller which is set through setController, the set controller will be used instead
  * of creating a new one.
  * @param Request $request
  * @return Controller
  * @throws zibo\ZiboException when no object factory has been set
  * @throws zibo\ZiboException when the controller could not be created
  */
 protected function getController(Request $request)
 {
     if ($this->controller && $request->getControllerName() == get_class($this->controller)) {
         return $this->controller;
     }
     if ($this->objectFactory === null) {
         throw new ZiboException('Could not create controller ' . $request->getControllerName() . ': no ObjectFactory set');
     }
     try {
         $controller = $this->objectFactory->create($request->getControllerName(), self::INTERFACE_CONTROLLER);
     } catch (ZiboException $e) {
         throw new ZiboException('Could not create controller ' . $request->getControllerName(), 0, $e);
     }
     return $controller;
 }
Exemple #14
0
 /**
  * Creates the opcode cache i/o from the Zibo configuration
  * @return zibo\library\cache\io\OpCacheIO
  */
 public static function createIOFromConfig()
 {
     $class = Zibo::getInstance()->getConfigValue(self::CONFIG_IO);
     if (!$class) {
         throw new ZiboException('No opcode cache implementation set. Please set the ' . self::CONFIG_IO . ' configuration value.');
     }
     $objectFactory = new ObjectFactory();
     return $objectFactory->create($class, self::INTERFACE_IO);
 }
Exemple #15
0
 /**
  * Deliver this message to the mail transport
  * @param array $variables Variables for the mail
  * @param zibo\library\mail\transport\Mail $transport The transport implementation to use, if not provided, the transport will be provided throught the Zibo configuration
  * @return null
  */
 public function send(array $variables = array(), Transport $transport = null)
 {
     if ($transport === null) {
         $objectFactory = new ObjectFactory();
         $transport = $objectFactory->createFromConfig(self::CONFIG_TRANSPORT, self::DEFAULT_TRANSPORT, self::INTERFACE_TRANSPORT);
     }
     $transport->send($this, $variables);
 }
Exemple #16
0
 private function setDependencyInjector()
 {
     // creates the dependency injector
     $this->dependencyInjector = new DependencyInjector();
     // gets the dependency container through the configuration
     $dependencyIO = $this->getConfigValue(self::CONFIG_DEPENDENCY_IO);
     if ($dependencyIO) {
         $objectFactory = new ObjectFactory();
         $dependencyIO = $objectFactory->create($dependencyIO, self::INTERFACE_DEPENDENCY_IO);
         $container = $dependencyIO->getContainer($this);
         $this->dependencyInjector->setContainer($container);
         $this->dependencyInjector->setInstance($objectFactory);
     }
     // set Zibo to the dependency injector
     $this->dependencyInjector->setInstance($this);
     $this->dependencyInjector->setInstance($this->getEnvironment(), self::INTERFACE_ENVIRONMENT);
     $this->dependencyInjector->setInstance($this->fileBrowser, self::INTERFACE_FILE_BROWSER);
 }
 /**
  * Action to create a diagram of the models
  * @return null
  */
 public function erdAction()
 {
     if (!class_exists(self::CLASS_ERD) || func_num_args()) {
         $this->setError404();
         return;
     }
     ini_set('max_execution_time', '300');
     ini_set('memory_limit', '512M');
     $models = ModelManager::getInstance()->getModels(true);
     $objectFactory = new ObjectFactory();
     $layout = $objectFactory->createFromConfig(self::CONFIG_ERD_LAYOUT, self::DEFAULT_ERD_LAYOUT, self::INTERFACE_ERD_LAYOUT);
     $erd = new Erd();
     $erd->setLayout($layout);
     $file = $erd->getFile($models);
     $this->setDownloadView($file);
 }
Exemple #18
0
 /**
  * Gets the negotiator implementation to use for locale negotiation.
  *
  * You can configure which class is being used with the configuration key "i18n.negotiator".
  *
  * @return zibo\library\i18n\locale\negotiator\Negotiator
  */
 private function getNegotiator()
 {
     if (!$this->negotiator) {
         $objectFactory = new ObjectFactory();
         $this->negotiator = $objectFactory->createFromConfig(self::CONFIG_NEGOTIATOR, self::CLASS_NEGOTIATOR, self::INTERFACE_NEGOTIATOR);
     }
     return $this->negotiator;
 }
 /**
  * Registers a captcha in the manager
  * @param string $name Internal name of the captcha
  * @param string $className Class name of the captcha
  * @return null
  * @throws zibo\ZiboException when the internal name or class name is empty or invalid
  * @throws zibo\ZiboException when the captcha does not exist or is not a valid captcha class
  */
 public function registerCaptcha($name, $className)
 {
     if (String::isEmpty($name)) {
         throw new ZiboException('Provided name is empty');
     }
     if (String::isEmpty($className)) {
         throw new ZiboException('Provided captcha class name is empty');
     }
     $objectFactory = new ObjectFactory();
     $this->captchas[$name] = $objectFactory->create($className, self::INTERFACE_CAPTCHA);
     if (!$this->defaultCaptchaName) {
         $this->defaultCaptchaName = $name;
     }
 }
 /**
  * Gets the view
  * @param array $result
  * @param joppa\content\model\ContentProperties $properties
  * @param integer $pages
  * @param integer $page
  * @return joppa\content\view\ContentView
  */
 private function getView(array $result, ContentProperties $contentProperties, $pages = 1, $page = 1)
 {
     $view = $contentProperties->getView();
     $listViews = ContentViewFactory::getInstance()->getOverviewViews();
     if (!array_key_exists($view, $listViews)) {
         return null;
     }
     $viewClass = $listViews[$view];
     $paginationProperties = null;
     if ($contentProperties->willShowPagination() && $pages > 1) {
         $paginationUrl = $this->request->getBasePath() . Request::QUERY_SEPARATOR . self::ACTION_PAGE . Request::QUERY_SEPARATOR . '%page%';
         $paginationProperties = new PaginationProperties($paginationUrl, $pages, $page);
     }
     $moreUrl = null;
     if ($contentProperties->willShowMoreLink()) {
         $node = $this->models[NodeModel::NAME]->getNode($contentProperties->getMoreNode(), 0, $this->locale);
         $moreUrl = $this->request->getBaseUrl() . Request::QUERY_SEPARATOR . $node->getRoute();
     }
     $objectFactory = new ObjectFactory();
     $view = $objectFactory->create($viewClass, ContentViewFactory::INTERFACE_OVERVIEW);
     $view->setContent($this->properties->getWidgetId(), $result, $contentProperties, $paginationProperties, $moreUrl);
     return $view;
 }
 /**
  * Loads the data managers from the Zibo configuration
  * @return null
  */
 private function loadManagers()
 {
     $this->managers = array();
     $objectFactory = new ObjectFactory();
     $managers = Zibo::getInstance()->getConfigValue(self::CONFIG_MANAGERS);
     foreach ($managers as $name => $managerClass) {
         try {
             $manager = $objectFactory->create($managerClass, self::INTERFACE_MANAGER);
             $this->managers[$name] = $manager;
         } catch (Exception $exception) {
             Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1);
         }
     }
 }
 /**
  * Get the model from the model element
  * @param DOMElement $modelElement model element in the xml root element
  * @param zibo\library\filesystem\File $file the file which is being read
  * @return zibo\library\orm\Model Model instance created from the read model definition
  * @throws zibo\library\orm\exception\OrmException when the model element has no name attribute
  */
 protected function getModelFromElement(DOMElement $modelElement, File $file)
 {
     $modelName = $modelElement->getAttribute(self::ATTRIBUTE_NAME);
     if ($modelName == null) {
         throw new OrmException('No ' . self::ATTRIBUTE_NAME . ' attribute found for ' . self::TAG_MODEL . ' tag in ' . $file->getPath());
     }
     $group = $modelElement->getAttribute(self::ATTRIBUTE_GROUP) ? $modelElement->getAttribute(self::ATTRIBUTE_GROUP) : null;
     $modelClassName = $modelElement->hasAttribute(self::ATTRIBUTE_MODEL_CLASS) ? $modelElement->getAttribute(self::ATTRIBUTE_MODEL_CLASS) : ModelManager::DEFAULT_MODEL;
     $dataClassName = $modelElement->hasAttribute(self::ATTRIBUTE_DATA_CLASS) ? $modelElement->getAttribute(self::ATTRIBUTE_DATA_CLASS) : ModelMeta::CLASS_DATA;
     $isLogged = $modelElement->getAttribute(self::ATTRIBUTE_LOG) ? Boolean::getBoolean($modelElement->getAttribute(self::ATTRIBUTE_LOG)) : false;
     $willBlockDeleteWhenUsed = $modelElement->getAttribute(self::ATTRIBUTE_WILL_BLOCK_DELETE) ? Boolean::getBoolean($modelElement->getAttribute(self::ATTRIBUTE_WILL_BLOCK_DELETE)) : false;
     $modelTable = new ModelTable($modelName, $isLogged);
     $modelTable->setGroup($group);
     $modelTable->setWillBlockDeleteWhenUsed($willBlockDeleteWhenUsed);
     $fields = $this->getFieldsFromElement($modelElement, $file, $modelName);
     foreach ($fields as $field) {
         $modelTable->addField($field);
     }
     $this->setIndexesFromElement($modelElement, $modelTable);
     $this->setFormatsFromElement($modelElement, $modelTable);
     $modelMeta = new ModelMeta($modelTable, $dataClassName);
     $objectFactory = new ObjectFactory();
     return $objectFactory->create($modelClassName, ModelManager::INTERFACE_MODEL, array($modelMeta));
 }
Exemple #23
0
 /**
  * Constructs a new translation manager
  * @return null
  *
  * @uses zibo\library\ObjectFactory::createFromConfig()
  */
 public function __construct()
 {
     $objectFactory = new ObjectFactory();
     $this->io = $objectFactory->createFromConfig(self::CONFIG_IO, self::CLASS_IO, self::INTERFACE_IO);
     $this->translators = array();
 }
 /**
  * Initializes the hash algorithm from the Zibo configuration
  * @param zibo\core\Zibo $zibo The Zibo instance
  * @param zibo\library\ObjectFactory $objectFactory Instance of an object factory
  * @return null
  */
 private function initializeHashAlgorithm(Zibo $zibo, ObjectFactory $objectFactory)
 {
     $hashAlgorithms = $zibo->getConfigValue(EncryptionModule::CONFIG_HASH_ALGORITHM);
     $hashAlgorithmName = $zibo->getConfigValue(self::CONFIG_HASH_ALGORITHM, self::DEFAULT_HASH_ALGORITHM);
     if (!array_key_exists($hashAlgorithmName, $hashAlgorithms)) {
         throw new ZiboException('Provided password hash algorithm ' . $hashAlgorithmName . ' could not be found');
     }
     $hashAlgorithmClass = $hashAlgorithms[$hashAlgorithmName];
     $this->hashAlgorithm = $objectFactory->create($hashAlgorithmClass, EncryptionModule::INTERFACE_HASH_ALGORITHM);
 }
 /**
  * Get the route I/O implementation. When no implementation is provided through the constructor,
  * a new implementation will be constructed based on the configuration.
  * @return zibo\core\router\io\RouterIO
  */
 protected final function getIO()
 {
     if ($this->io) {
         return $this->io;
     }
     $objectFactory = new ObjectFactory();
     $this->io = $objectFactory->createFromConfig(self::CONFIG_ROUTER_IO, self::DEFAULT_ROUTER_IO, self::CLASS_ROUTER_IO);
     return $this->io;
 }
 /**
  * Gets the view
  * @param joppa\content\model\ContentProperties $properties
  * @param joppa\model\content\Content $content
  * @return joppa\content\view\ContentView
  */
 private function getView(ContentProperties $contentProperties, $content)
 {
     $view = $contentProperties->getView();
     $detailViews = ContentViewFactory::getInstance()->getDetailViews();
     if (!array_key_exists($view, $detailViews)) {
         return null;
     }
     $viewClass = $detailViews[$view];
     $objectFactory = new ObjectFactory();
     $view = $objectFactory->create($viewClass, ContentViewFactory::INTERFACE_DETAIL);
     $view->setContent($this->properties->getWidgetId(), $content, $contentProperties);
     return $view;
 }
 /**
  * Load the content mappers as defined in the Zibo configuration
  * @return null
  */
 private function loadMappers()
 {
     $mappers = Zibo::getInstance()->getConfigValue(self::CONFIG_MAPPERS, array());
     $objectFactory = new ObjectFactory();
     $this->mappers = array();
     foreach ($mappers as $type => $className) {
         $mapper = $objectFactory->create($className, self::CLASS_MAPPER);
         $this->mappers[$type] = $mapper;
     }
 }