Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] problem z klasa - nie wyświetla nic, klasa pisana dla zabawy i nauki
Balon
post 14.08.2006, 12:21:01
Post #1





Grupa: Zarejestrowani
Postów: 422
Pomógł: 0
Dołączył: 14.12.2005
Skąd: Wałbrzych

Ostrzeżenie: (0%)
-----


  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


--------------------
Postura wielka i morda wredna, jestem Balon, kozak z osiedla !
bzdury.pl - Królestwo rozrywki
Go to the top of the page
+Quote Post
nospor
post 14.08.2006, 12:41:55
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




  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?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Balon
post 14.08.2006, 12:56:38
Post #3





Grupa: Zarejestrowani
Postów: 422
Pomógł: 0
Dołączył: 14.12.2005
Skąd: Wałbrzych

Ostrzeżenie: (0%)
-----


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....


--------------------
Postura wielka i morda wredna, jestem Balon, kozak z osiedla !
bzdury.pl - Królestwo rozrywki
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 15.07.2025 - 23:52