Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] problem z klasa - nie wyświetla nic
Forum PHP.pl > Forum > Przedszkole
Balon
  1. <?php
  2.  
  3. class cleanCss
  4. {
  5. public $input;
  6. public $output;
  7. public $debug;
  8. public $cache_path;
  9.  
  10. function __construct( $debug = false )
  11. {
  12. $this->debug = $debug;
  13. }
  14.  
  15. function clean( $input, $cache_path )
  16. {
  17. $this->input = $input;
  18. $this->cache_path = $cache_path;
  19.  
  20. if( preg_match_all( '!/*(.*?)*/!', $this->input, $out ) )
  21. {
  22. $this->output = preg_replace( '!/*(.*?)*/!', '', $this->input );
  23. $this->output = trim( $this->output );
  24. if( $this->debug == true )
  25. $this->log( $out );
  26. $this->save();
  27. }
  28. else 
  29. $this->output = $this->input;
  30. return $this->output;
  31. }
  32.  
  33. function save()
  34. {
  35. $f = fopen( $this->cache_path . 'style.css', 'w+' );
  36. fwrite( $f, $this->output );
  37. fclose( $f );
  38. }
  39.  
  40. function log( $array )
  41. {
  42. $i = 0;
  43. foreach( $array as $arr )
  44. {
  45. if( $i > 0 ) { echo 'Deleted unnecessary contents. <br/><pre>' . $arr[0] . '</pre><hr/>'; }; $i++;
  46. }
  47. }
  48. }
  49.  
  50. class cacheCss
  51. {
  52. const OPTIMIZE_CSS = true;
  53. public $csspath = 'style.css';
  54. public $cleaner;
  55. public $csscachepath = 'cache/css/';
  56.  
  57. function __construct( $file, $cleanobject )
  58. {
  59. $this->csspath = $file;
  60. $this->cleaner = $cleanobject;
  61. }
  62.  
  63. function load()
  64. {
  65. if( $this->checkInCache() )
  66. return $this->loadFromCache();
  67. else
  68. {
  69. switch( self::OPTIMIZE_CSS )
  70. {
  71. case true: 
  72. return $this->cleaner->clean( $this->loadFromFile(), $this->csscachepath );
  73. case false:
  74. return $this->loadFromFile();
  75. }
  76. }
  77. return false;
  78. }
  79.  
  80. function loadFromFile()
  81. {
  82. return implode( "n", file( $this->csspath ) );
  83. }
  84.  
  85. function loadFromCache()
  86. {
  87. return implode( "n", file( $this->csscachepath . 'style.css' ) );
  88. }
  89.  
  90. function checkInCache()
  91. {
  92. return file_exists( $this->csscachepath . $this->csspath );
  93. }
  94. }
  95.  
  96. $css = new cacheCss( 'style.css', new cleanCss( true ) );
  97. $css->load();
  98. ?>


i teraz problem jest taki ze wywolanie metody load obiektu cachecss ma powodowac wywolanie metody clean obiektu cleancss, jednak niby jest on wykonywany, ale nic nie zwraca.... chociaz w kazdym przypadku poowinien zwracac cokolwiek ..

prosze o pomoc
nospor
  1. <?php
  2. $css->load();
  3. ?>
blinksmiley.gif i skad wiesz, ze nic nie zwraca? Ani te tyego nie przechwytujesz, ani nie wyswietlasz wiec skad ta mysl?
Balon
a tak zapomniałem. Wyświetlalem to, potem to usunelem ale ogolnie zwraca niezoptymalizowany plik css.....

przykladowo wczytuje ten plik
Kod
}
/**  
* ID
*/
#main
{
  width: 676px;
  margin: 0 auto;
}
#main img
{
  border: 0px;
}
#headLeft
{
  float: left;
  padding-bottom: 5px;
  padding-left: 10px;
}
#headRight
{  
  font-weight: bold;
  color: #BABABA;
  float: right;
  padding-right: 8px;
}
(....)


jednak zwraca mi to samo, bez usunietych komentarzy... tak jakby regexp nie sprawdzal sie i zwracal input czyli to co weszlo do cleanera...na poczatku jak byla tylko klasa cleanera to dzialalo i czyscilo css z komentarzy, po polaczeniu juz tak nie jest....
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.