Example #1
0
 /**
  * Create a view and get its content
  *
  * @param string  Name of view
  * @param array   Data to pass to the view
  * @return \Kofradia\Viev
  */
 public static function forge($name, $data = array())
 {
     $path = PATH_APP . "/views/{$name}.php";
     $view = new static($path);
     $view->setData($data);
     return $view->render();
 }
Example #2
0
 /**
  * Create a thumbnail
  */
 static function create($source, $options = array())
 {
     // Create thumb
     $thumb = new static();
     // Load
     $thumb->load($source);
     // Set properties
     $properties = array('type', 'quality', 'alignX', 'alignY', 'background');
     // Loop
     foreach ($properties as $property) {
         // If set
         if (isset($options[$property])) {
             // Set it
             $thumb->{$property} = $options[$property];
         }
     }
     // If there's width
     if (isset($options['width']) && ($width = $options['width'])) {
         // Set width
         $thumb->width = $width;
     }
     // If there's height
     if (isset($options['height']) && ($height = $options['height'])) {
         // Set height
         $thumb->height = $height;
     }
     // Resize
     $thumb->resize();
     // Render and return
     return $thumb->render();
 }
Example #3
0
 /**
  * @param string $templatePath
  * @param array $data
  *
  * @return string
  */
 public static function renderTemplate(string $templatePath, array $data = []) : string
 {
     if (substr($templatePath, 0, 1) != '/') {
         $templatePath = AbstractApp::getAppRoot() . '/' . $templatePath;
     }
     $phtml = new static($templatePath);
     $phtml->addDatas($data);
     return $phtml->render();
 }
 public static function factory(RendererInterface $renderer, DataObject $object, $urlType, array $attributes = array())
 {
     $element = new static();
     $element->setView($renderer);
     $element->setObject($object);
     $element->setAttributes($attributes);
     $element->setUrlType($urlType);
     return $element->render();
 }
Example #5
0
File: Json.php Project: akeeba/fof
 /**
  * Render a HAL document in JSON format
  *
  * @param   array  $options  Rendering options. You can currently only set json_options (json_encode options)
  *
  * @return  string  The JSON representation of the HAL document
  */
 public function render($options = array())
 {
     if (isset($options['data_key'])) {
         $this->_dataKey = $options['data_key'];
     }
     if (isset($options['json_options'])) {
         $jsonOptions = $options['json_options'];
     } else {
         $jsonOptions = 0;
     }
     $serialiseThis = new \stdClass();
     // Add links
     $collection = $this->_document->getLinks();
     $serialiseThis->_links = new \stdClass();
     foreach ($collection as $rel => $links) {
         if (!is_array($links)) {
             $serialiseThis->_links->{$rel} = $this->_getLink($links);
         } else {
             $serialiseThis->_links->{$rel} = array();
             foreach ($links as $link) {
                 array_push($serialiseThis->_links->{$rel}, $this->_getLink($link));
             }
         }
     }
     // Add embedded documents
     $collection = $this->_document->getEmbedded();
     if (!empty($collection)) {
         $serialiseThis->_embedded = new \stdClass();
         foreach ($collection as $rel => $embeddeddocs) {
             $serialiseThis->_embedded->{$rel} = array();
             if (!is_array($embeddeddocs)) {
                 $embeddeddocs = array($embeddeddocs);
             }
             foreach ($embeddeddocs as $embedded) {
                 $renderer = new static($embedded);
                 array_push($serialiseThis->_embedded->{$rel}, $renderer->render($options));
             }
         }
     }
     // Add data
     $data = $this->_document->getData();
     if (is_object($data)) {
         if ($data instanceof DataModel) {
             $data = $data->toArray();
         } else {
             $data = (array) $data;
         }
         if (!empty($data)) {
             foreach ($data as $k => $v) {
                 $serialiseThis->{$k} = $v;
             }
         }
     } elseif (is_array($data)) {
         $serialiseThis->{$this->_dataKey} = $data;
     }
     return json_encode($serialiseThis, $jsonOptions);
 }
Example #6
0
 public static function helpers()
 {
     static::$app = app();
     $link_to = new \Twig_SimpleFunction('link_to', function ($text, $route_alias, $data = [], $attributes = []) {
         $url = urlHelper($route_alias, $data);
         if (isset($attributes)) {
             $cnt = '';
             foreach ($attributes as $key => $value) {
                 $cnt .= $value[0] . '="' . $value[1] . '" ';
             }
         }
         echo '<a href="' . $url . '" ' . $cnt . '>' . $text . '</a>';
     });
     $link_to_remote = new \Twig_SimpleFunction('link_to_remote', function ($text, $url, $attributes) {
         if (isset($attributes)) {
             $cnt = '';
             foreach ($attributes as $key => $value) {
                 $cnt .= $value[0] . '="' . $value[1] . '" ';
             }
         }
         echo '<a href="' . $url . '" ' . $cnt . '>' . $text . '</a>';
     });
     $debugBarHead = new \Twig_SimpleFunction('debugBarHead', function () {
         $app = app();
         if (!$app->isProd()) {
             static::$debugbarRender = $app->debugbar;
             $test = static::$debugbarRender;
             static::$render = $test->getJsRender();
             echo static::$render->renderHead();
         } else {
             echo '';
         }
     });
     $debugBarBody = new \Twig_SimpleFunction('debugBarBody', function () {
         $app = app();
         if (!$app->isProd()) {
             echo static::$debugbarRender->render();
         } else {
             echo '';
         }
     });
     $flash = new \Twig_SimpleFunction('flash', function () {
         echo flash()->display(null, false);
     });
     $dd = new \Twig_SimpleFunction('dd', function ($data) {
         dd($data);
     });
     return ['flash' => $flash, 'debugBarHead' => $debugBarHead, 'debugBarBody' => $debugBarBody, 'link_to' => $link_to, 'link_to_remote' => $link_to_remote, 'dd' => $dd];
 }
Example #7
0
 /**
  * Execute the command.
  *
  * @param Application $app The application instance
  *
  * @return mixed
  */
 public static function execute(Application $app)
 {
     static::$base = dirname(__DIR__) . '/templates/help/';
     $help = new static($app->command ?: 'help');
     $help->render();
 }
Example #8
0
 /**
  * load
  *
  * @param string $file
  * @param array  $data
  *
  * @return  string
  */
 public function load($file, $data = null)
 {
     $data = $this->data->bind(new Data($data));
     $renderer = new static($this->paths, $this->config);
     return $renderer->render($file, $data);
 }
 /**
  * Prepare a response from the given value.
  *
  * If the value is not a response, it will be converted into a response
  * instance and the content will be cast to a string.
  *
  * @param  mixed     $response
  * @return Response
  */
 public static function prepare($response)
 {
     if (!$response instanceof Response) {
         $response = new static($response);
     }
     // We'll need to force the response to be a string before closing the session,
     // since the developer may be using the session within a view, and we can't
     // age the flash data until the view is rendered.
     //
     // Since this method is used by both the Route and Controller classes, it is
     // a convenient spot to cast the application response to a string before it
     // is returned to the main request handler.
     $response->render();
     return $response;
 }
Example #10
0
 /**
  * Adds a fieldset object to the table.
  *
  * @param  Fieldset $fieldset
  *
  * @since 2.0
  */
 public function renderFieldset(Fieldset $fieldset)
 {
     // Create a new renderer and render the content
     $fieldsetRenderer = new static($this->csrfProvider);
     // Generate all the content
     foreach ($fieldset as $item) {
         $fieldsetRenderer->render($item);
     }
     $content = $fieldsetRenderer->getRenderedForm();
     // Create the fieldset tag and add the content
     $tag = Html::tag('fieldset', $fieldset->getAttributes(), $content);
     // Make sure everything is added to the parent table
     $cell = new Table\Cell($tag);
     $cell->setAttributes(['colspan' => 2]);
     $this->table->addCell($cell);
     $this->table->addRow();
     return '';
 }
Example #11
0
 /**
  * Export
  *
  * @param Di $di
  * @param array $runtimeClasses
  * @return void
  */
 public static function export(Di $di, array $runtimeClasses = array())
 {
     $console = new static($di);
     $console->addRuntimeClasses($runtimeClasses);
     $console->render($di);
 }
Example #12
0
 public static function setRender($render)
 {
     static::$render = $render;
 }
Example #13
0
 public function import($in, $data = null)
 {
     $new = new static($in, $this->getOutputStream(), $this->getRouter(), $data);
     $new->render();
     return;
 }
Example #14
0
 /**
  * Initializes a helper with access to the template, and if needed, some
  * parameters and content,
  * validates its properties and returns its HTML representation
  * @static
  * @param Cognosys\Template $template
  * @param array $params
  * @param mixed $content Tipically, a string, an array or a Closure
  * @return string
  */
 public static function create($template, array $params = array(), $content = null)
 {
     $helper = new static($template, $params, $content);
     $helper->validate();
     return $helper->render($content);
 }
Example #15
0
 public static function page($template, $data = array())
 {
     $tpl = new static();
     $tpl->assign('data', $data);
     echo $tpl->render($template);
 }
Example #16
0
 private function generateFromArray($attributes)
 {
     $bar = new static();
     foreach ($attributes as $attribute) {
         $exploded = explode('=', $attribute);
         $method = $exploded[0];
         $vars = isset($exploded[1]) ? $exploded[1] : null;
         if (isset($vars)) {
             $bar->{$method}($vars);
         } else {
             $bar->{$method}();
         }
     }
     // Now to remove the outer divs
     $string = $bar->render();
     $string = str_replace('<div class=\'progress\'>', '', $string);
     $string = str_replace('</div></div>', '</div>', $string);
     return $string;
 }
Example #17
0
 public static function compile($path, $vars = array())
 {
     $braces = new static($path);
     return $braces->render($vars);
 }
Example #18
0
 /**
  * @param float|int $number
  * @param string $outUnit
  * @param Number\NumberFormat $format
  * @return Number\INumberFormat
  */
 public static function recount($number, $outUnit = NULL, Number\NumberFormat $format = NULL)
 {
     $unit = new static($outUnit);
     $unit->setNumber($number);
     if ($format) {
         $unit->setFormat($format);
     }
     return $unit->render();
 }
Example #19
0
 /**
  * Run render site
  *
  * @return \BX\MVC\SiteController
  */
 public static function run()
 {
     $instanse = new static();
     return $instanse->render();
 }
Example #20
0
 /**
  * Debug main method
  *
  * @param $var var to see
  * @param int $debugTracePosition
  */
 public static function debug($var, $debugTracePosition = 1)
 {
     $deb = null;
     if (static::$conf['debug'] == true) {
         $deb = new static();
         $deb->setVar($var)->setDebugTracePosition($debugTracePosition);
         if (static::$conf['render_local'] == true) {
             $deb->render();
         }
     }
     return $deb;
 }
Example #21
0
 /**
  * Render a layout with the same include paths & options
  *
  * @param   object  $layoutId     Object which properties are used inside the layout file to build displayed output
  * @param   mixed   $displayData  Data to be rendered
  *
  * @return  string  The necessary HTML to display the layout
  *
  * @since   3.2
  */
 public function sublayout($layoutId, $displayData)
 {
     // Sublayouts are searched in a subfolder with the name of the current layout
     if (!empty($this->layoutId)) {
         $layoutId = $this->layoutId . '.' . $layoutId;
     }
     $sublayout = new static($layoutId, $this->basePath, $this->options);
     $sublayout->includePaths = $this->includePaths;
     return $sublayout->render($displayData);
 }
Example #22
0
 /**
  * mengambil output dari suatu file view
  * @param string $view nama file view yang akan di fetch
  * @param array $data variable-variable yang akan di outputkan
  * @return View instance dari kelas ini
  */
 public static function fetch($view = null, $data = null)
 {
     $instance = new static($view);
     return $instance->render(false, $data);
 }