Exemplo n.º 1
0
 /**
  * @param $base_path
  * @param string $file
  * @return bool|\SimpleXMLElement
  */
 public function loadXml($base_path, $file)
 {
     $file = str_replace('.xml', '', $file);
     $manifest_path = FilesystemPath::find($base_path, $file . '.xml');
     if (!$manifest_path) {
         return false;
     }
     return simplexml_load_file($manifest_path, __NAMESPACE__ . '\\XmlElement');
 }
Exemplo n.º 2
0
 /**
  * @param $type
  * @throws ExtensionException
  */
 public static function get($type)
 {
     $type = strtolower($type);
     if ($file = FilesystemPath::find(self::addIncludePath(), $type . DIRECTORY_SEPARATOR . $type . '.php')) {
         require_once $file;
         $class_name = __NAMESPACE__ . '\\ExtensionType' . ucfirst($type);
         if (!class_exists($class_name)) {
             throw new ExtensionException(sprintf('Extension type "%s" not found!', ucfirst($type)));
         }
         $required_traits = ['Cyan\\Framework\\TraitSingleton'];
         $reflection_class = new ReflectionClass($class_name);
         foreach ($required_traits as $required_trait) {
             if (!in_array($required_trait, $reflection_class->getTraitNames())) {
                 throw new ExtensionException(sprintf('%s class must use %s', $class_name, $required_trait));
             }
         }
         if (!is_callable([$class_name, 'register'])) {
             throw new ExtensionException(sprintf('%s class must implement register method', $class_name));
         }
         return $class_name::getInstance();
     }
     throw new ExtensionException(sprintf('Extension "%s" not found!', ucfirst($type)));
 }
Exemplo n.º 3
0
 /**
  * Render layout
  *
  * @param null $layout
  * @param array $data
  * @param array $options
  *
  * @return string
  *
  * @since 1.0.0
  */
 public function render($layout = null, array $data = [], array $options = [])
 {
     if (!empty($layout)) {
         $newLayout = self::display($layout, $data, $options);
         foreach (array_diff($this->addPath(), $newLayout->addPath()) as $base_path) {
             $newLayout->addPath($base_path);
         }
         foreach ($this->getContainers() as $container_name) {
             if (!$newLayout->hasContainer($container_name)) {
                 $newLayout->setContainer($container_name, $this->getContainer($container_name));
                 if ($container_name == 'view' && $this->getContainer('view')->hasContainer('application') && !$newLayout->hasContainer('application')) {
                     $newLayout->setContainer('application', $this->getContainer('view')->getContainer('application'));
                 }
             }
         }
         return $newLayout->render();
     }
     $output = '';
     $layout_path = str_replace('.', DIRECTORY_SEPARATOR, $this->layout) . '.php';
     if ($file = FilesystemPath::find(self::addIncludePath(), $layout_path)) {
         $Cyan = \Cyan::initialize();
         ob_start();
         include $file;
         $output = ob_get_clean();
     }
     return $output;
 }
Exemplo n.º 4
0
 /**
  * @param $file_path
  *
  * @return bool
  *
  * @since 1.0.0
  */
 public function writeFile($format, $file_path)
 {
     switch ($format) {
         case 'php':
             if (!is_array($this->data)) {
                 throw new ConfigException('Config data must be an array to write php files');
             }
             $data = '<?php' . chr(13);
             $data .= 'return ' . var_export($this->data, true) . ';' . chr(13);
             break;
         case 'json':
             $data = json_encode($this->data);
             break;
     }
     FilesystemPath::create(dirname($file_path));
     return file_put_contents($file_path, $data);
 }
Exemplo n.º 5
0
 /**
  * Load a field type
  *
  * @param $type
  * @param $namespace
  * @param bool $new
  *
  * @return bool|string
  *
  * @since 1.0.0
  */
 private function loadField($type, $namespace, $new = false)
 {
     $signature = md5($type);
     if (isset($this->elements[$signature]) && !is_a($this->elements[$signature], '__PHP_Incomplete_Class') && $new === false) {
         return $this->elements[$signature];
     }
     $element_class = sprintf('%s\\FormField%s', $namespace, ucfirst(strtolower($type)));
     if (!class_exists($element_class)) {
         $dirs = self::addFieldPath();
         $file = sprintf('%s' . DIRECTORY_SEPARATOR . '%s.php', $type, $type);
         if ($element_path = FilesystemPath::find($dirs, $file)) {
             require_once $element_path;
         } else {
             $element_path = FilesystemPath::find($dirs, "null.php");
             require_once $element_path;
             $element_class = $namespace . '\\FormFieldNull';
         }
     }
     if (!class_exists($element_class)) {
         return false;
     }
     return $element_class;
 }
Exemplo n.º 6
0
 /**
  * Register routes into application
  */
 private function registerRoutes()
 {
     $App = $this->getContainer('application');
     $route_path = FilesystemPath::find(self::addIncludePath(), 'routes.php');
     $class_base = $this->component_name;
     if ($route_path) {
         $config_routes = (require_once $route_path);
     }
     if (!isset($config_routes)) {
         return;
     }
     // check route routes
     if (isset($config_routes['routes'])) {
         foreach ($config_routes['routes'] as $route_uri => $route_config) {
             $this->assignRoute($route_uri, $route_config, $class_base, $route_path);
         }
     }
     // check route config
     if (isset($config_routes['config']) && !empty($config_routes['config'])) {
         // define default route
         if (isset($config_routes['config']['default_route'])) {
             if (!isset($config_routes['default_route_parameters'])) {
                 $config_routes['default_route_parameters'] = [];
             }
             // set default route
             $App->Router->setDefaultRoute($config_routes['config']['default_route'], $config_routes['default_route_parameters']);
         }
     }
 }