Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TStyle.php

Documentation is available at TStyle.php

  1. <?php
  2. namespace Adianti\Widget\Base;
  3.  
  4. use Adianti\Control\TPage;
  5. use Adianti\Widget\Base\TElement;
  6.  
  7. /**
  8.  * StyleSheet Manager
  9.  *
  10.  * @version    7.4
  11.  * @package    widget
  12.  * @subpackage base
  13.  * @author     Pablo Dall'Oglio
  14.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  15.  * @license    http://www.adianti.com.br/framework-license
  16.  */
  17. class TStyle
  18. {
  19.     private $name;           // stylesheet name
  20.     private $properties;     // properties
  21.     static  private $loaded// array of loaded styles
  22.     static  private $styles;
  23.     
  24.     /**
  25.      * Class Constructor
  26.      * @param $mame Name of the style
  27.      */
  28.     public function __construct($name)
  29.     {
  30.         $this->name $name;
  31.         $this->properties array();
  32.     }
  33.     
  34.     /**
  35.      * Import style
  36.      * @param $style Style file name
  37.      */
  38.     public static function importFromFile($filename)
  39.     {
  40.         $style new TElement('style');
  41.         $style->addfile_get_contents$filename ) );
  42.         $style->show();
  43.     }
  44.     
  45.     /**
  46.      * Returns the style name
  47.      */
  48.     public function getName()
  49.     {
  50.         return $this->name;
  51.     }
  52.     
  53.     /**
  54.      * Find a style by its properties
  55.      * @object style object
  56.      */
  57.     public static function findStyle($object)
  58.     {
  59.         if (self::$styles)
  60.         {
  61.             foreach (self::$styles as $stylename => $style)
  62.             {
  63.                 if ((array)$style->properties === (array)$object->properties)
  64.                 {
  65.                     return $stylename;
  66.                 }
  67.             }
  68.         }
  69.     }
  70.     
  71.     /**
  72.      * Executed whenever a property is assigned
  73.      * @param  $name    = property's name
  74.      * @param  $value   = property's value
  75.      */
  76.     public function __set($name$value)
  77.     {
  78.         // replaces "_" by "-" in the property's name
  79.         $name str_replace('_''-'$name);
  80.         
  81.         // store the assigned tag property
  82.         $this->properties[$name$value;
  83.     }
  84.     
  85.     /**
  86.      * Executed whenever a property is read
  87.      * @param  $name    = property's name
  88.      */
  89.     public function __get($name)
  90.     {
  91.         // replaces "_" by "-" in the property's name
  92.         $name str_replace('_''-'$name);
  93.         
  94.         return $this->properties[$name];
  95.     }
  96.     
  97.     /**
  98.      * Return if the style has any content
  99.      */
  100.     public function hasContent()
  101.     {
  102.         return count($this->properties0;
  103.     }
  104.     
  105.     /**
  106.      * Returns the style content
  107.      */
  108.     public function getContent()
  109.     {
  110.         // open the style
  111.         $style '';
  112.         $style.= "    .{$this->name}\n";
  113.         $style.= "    {\n";
  114.         if ($this->properties)
  115.         {
  116.             // iterate the style properties
  117.             foreach ($this->properties as $name=>$value)
  118.             {
  119.                 $style.= "        {$name}: {$value};\n";
  120.             }
  121.         }
  122.         $style.= "    }\n";
  123.         return $style;
  124.     }
  125.     
  126.     /**
  127.      * Return the style inline code
  128.      */ 
  129.     public function getInline()
  130.     {
  131.         $style = '';
  132.         if ($this->properties)
  133.         {
  134.             // iterate the style properties
  135.             foreach ($this->properties as $name=>$value)
  136.             {
  137.                 $name = str_replace('_', '-', $name);
  138.                 $style.= "{$name}: {$value};";
  139.             }
  140.         }
  141.         
  142.         return $style;
  143.     }
  144.     
  145.     /**
  146.      * Show the style
  147.      */
  148.     public function show( $inline = FALSE)
  149.     {
  150.         // check if the style is already loaded
  151.         if (!isset(self::$loaded[$this->name]))
  152.         {
  153.             if ($inline)
  154.             {
  155.                 echo "    <style type='text/css' media='screen'>\n";
  156.                 echo $this->getContent();
  157.                 echo "    </style>\n";
  158.             }
  159.             else
  160.             {
  161.                 $style = $this->getContent();
  162.                 TPage::register_css($this->name$style);
  163.                 // mark the style as loaded
  164.                 self::$loaded[$this->nameTRUE;
  165.                 self::$styles[$this->name$this;
  166.             }
  167.         }
  168.     }