Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Klasa pluginow jako filtry
marcio
post 16.09.2009, 23:04:57
Post #1





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


Witam mam taki mini problem szukalem informacji na temat pluginow jaki filtry tzn jak dawac hooki albo napisac odpowiedni dekorator etc... bylo duzo metod na zrobienie tego jednak napotkalem sie na 2 ciekawe arty jeden po eng drugi po pl i wykorzystalem ich dzialanie.

System pluginow dziala system filtrow tez ale w 90% poniewaz nie zgadza mi sie kolejnosc funkcji.

Moja klasa filtrow:
  1. <?php
  2.  
  3. class PluginFilter {
  4.  
  5. private static $LoadPlugins = array();
  6. private $cfg;
  7.  
  8. public function __construct() {
  9.  
  10. $this -> cfg = Loader::load('Cfg');
  11.  
  12. }
  13.  
  14.  
  15. public function LoadFilter($PluginFilter) {
  16.  
  17. if(file_exists(DIR_PLUGINS_FILTERS.$PluginFilter.'.php')) {
  18.  
  19. require_once(DIR_PLUGINS_FILTERS.$PluginFilter.'.php');
  20.  
  21. }
  22.  
  23. $object = new $PluginFilter();
  24. self::$LoadPlugins[$PluginFilter] = new $PluginFilter();
  25. if(method_exists($object, 'onLoad')) $object -> onLoad();
  26.  
  27. }
  28.  
  29.  
  30. public function RemoveFilter($PluginFilter) {
  31.  
  32. if(!empty(self::$LoadPlugins[$PluginFilter])) {
  33.  
  34. $object = self::$LoadPlugins[$PluginFilter];
  35. if(method_exists($object, 'onUnload'))
  36. $object -> onUnload();
  37. unset(self::$LoadPlugins[$PluginFilter]);
  38.  
  39. }
  40.  
  41. }
  42.  
  43.  
  44. public function AddEvent($method, $params) {
  45.  
  46. foreach(self::$LoadPlugins as $NameFilter => $ObjFilter) {
  47.  
  48. if(method_exists($ObjFilter, $method)) {
  49.  
  50. call_user_func_array(array($ObjFilter, $method), $params);
  51.  
  52. }
  53.  
  54. }
  55.  
  56. }
  57.  
  58. public function __call($method, $params) {
  59.  
  60. if(method_exists($this, '_'.$method)) {
  61.  
  62. $this -> AddEvent('on_'.get_class($this).'_pre_'.$method, $params);
  63.  
  64. $funcResult = call_user_func_array(array($this, '_'.$method), $params);
  65.  
  66. $this -> AddEvent('on_'.get_class($this).'_post_'.$method, $funcResult);
  67.  
  68. return $funcResult;
  69.  
  70. }
  71.  
  72. }
  73.  
  74. }
  75.  
  76. ?>


Klasa bazowa uruchomiajaca plugin:
  1. <?php
  2.  
  3. require_once('libraries/PluginFilter.php');
  4.  
  5. class tester extends PluginFilter {
  6.  
  7. public function _test($arg) {
  8.  
  9. return '<b>'.$arg.'</b><Br>';
  10.  
  11. }
  12.  
  13. }
  14.  
  15. $test = new tester();
  16. $test -> LoadFilter('testplug');
  17. echo $test -> test('cos');
  18. $test -> RemoveFilter('testplug');
  19.  
  20. ?>

A tu klasa filtru:
  1. <?php
  2.  
  3. class testplug {
  4.  
  5. public function onLoad() {
  6.  
  7. echo('Poczatek<Br>');
  8.  
  9. }
  10.  
  11. public function on_tester_pre_test() {
  12.  
  13. echo('Przed funckja test<Br>');
  14.  
  15. }
  16.  
  17. public function on_tester_post_test($code) {
  18.  
  19. echo('<p style="font-size:18px;"><i>'.$code.'</i></p>');
  20.  
  21. }
  22.  
  23. public function onUnload() {
  24.  
  25. echo('Koniec<Br>');
  26.  
  27. }
  28.  
  29. }
  30.  
  31. ?>

I dane wyjsciowe:
Cytat
Poczatek
Przed funckja test
cos


cos
Koniec

No i jak widac nie zgadza sie wykonanie funkcji POST poniewaz wyswietla sie powiekszony tesk i pochylony jako 3 a nie jakos 4 w kolejnosci.

Tutaj jest to pokazane: http://marcio.ekmll.com/test.php

Dziekuje za odp.


--------------------
Zainteresowania: XML | PHP | MY(SQL)| C# for .NET | PYTHON
http://code.google.com/p/form-builider/
Moj blog
Go to the top of the page
+Quote Post
kfc4
post 17.09.2009, 18:15:26
Post #2





Grupa: Zarejestrowani
Postów: 195
Pomógł: 18
Dołączył: 7.10.2007

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


A czy możesz podlinkować te artykuły?
Go to the top of the page
+Quote Post
marcio
post 17.09.2009, 22:00:16
Post #3





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


http://www.sitepoint.com/forums/showthread.php?t=379440 topic o tym.

http://www.w3style.co.uk/?p=9 art

http://stackoverflow.com/questions/42/best...php-application hooki

http://carbolymer.ovh.org/wp/?p=15

http://carbolymer.ovh.org/wp/?p=18

http://mureakuha.com/koodikirjasto/791 art




i jeszcze to http://forum.php.pl/index.php?showtopic=34190&st=40 




Poskladalem wszystko do kupy jak mi pasowalo i wsio dziala komponenty i pluginy sie laduja wszystko pisalem sam i do tego dzialaja tez pluginy jako filtry dla komponentow lub pluginow.




Jesli chcesz moge przeslac ci caly system.




P.S pozostaje tylko problem z kolejnoscia tych 2 funkcji ale mam juz pomysl jak to objesc.

Ten post edytował marcio 17.09.2009, 22:01:00


--------------------
Zainteresowania: XML | PHP | MY(SQL)| C# for .NET | PYTHON
http://code.google.com/p/form-builider/
Moj blog
Go to the top of the page
+Quote Post
kfc4
post 18.09.2009, 16:47:28
Post #4





Grupa: Zarejestrowani
Postów: 195
Pomógł: 18
Dołączył: 7.10.2007

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


Tak, poprosił bym jeśli można.
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: 19.07.2025 - 14:28