Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Blad po przenosieniu bloga na inny server
Forum PHP.pl > Forum > PHP > Object-oriented programming
marcio
Witam wykupilem sobie server na linuxpl.com wczesniej moj blog byl na serverze z php 5.2.17 teraz na nowym hostingu chce sie poki co przerzucic na wersje 5.3.28(pozniej na 5.4.x ale poki co mam blad dotyczacy referencji ktorego nie mam pojecia jak poprawic)

Problema polega na tym ze daje mi blad w tej klasie:
  1. <?php
  2.  
  3. /**
  4. *Volta framework
  5.  
  6. *@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
  7. *@copyright Copyright (c) 2012, marcio
  8. *@version 1.0
  9. */
  10.  
  11. require_once(DIR_ABSTRACT.'Validation.php');
  12. require_once(DIR_INTERFACES.'IValidation.php');
  13.  
  14. class user extends Vf_Validation implements IValidation
  15. {
  16.  
  17. /**
  18. *Skladowa klasy ktora przechowywuje tresci bledow
  19. *@access protected
  20. */
  21. protected $error = array(
  22. 'pl' => array(
  23. 'banned' => 'To konto zostalo zbanowane',
  24. 'account_disabled' => 'To konto nie zostalo aktywowane',
  25. 'user_exists' => 'Uzytkownik o takiej nazwie juz istnieje'
  26. )
  27. );
  28.  
  29.  
  30. /**
  31. *Konstruktor ustawia konfiguracje walidatora
  32. *@access public
  33. *@param array $cfg
  34. */
  35. public function __construct($cfg)
  36. {
  37. parent::__construct();
  38. $this -> configure($cfg);
  39. }
  40.  
  41.  
  42. /**
  43. *Metoda ktora sprawdza walidacje danych na podstawie wczesniej ustawionej konfiguracji
  44. *@access public
  45. *@param string $object tresc do walidacji
  46. *@return bool|string
  47. */
  48. public function is_valid($object)
  49. {
  50. if($this -> get_option('check_ban'))
  51. {
  52. if(empty($object))
  53. {
  54. return true;
  55. }
  56.  
  57. $message = $this -> error[$this -> language -> get() -> getLang()]['banned']; //tutaj jest blad
  58. $ban = Vf_Orm::factory('Ban');
  59.  
  60. if($ban -> isBanned($object))
  61. {
  62. return $this -> set_error($message);
  63. }
  64. }
  65.  
  66.  
  67. if($this -> get_option('check_is_active'))
  68. {
  69. $request = new Vf_Request();
  70. if(empty($object))
  71. {
  72. return true;
  73. }
  74.  
  75. $message = $this -> error[$this -> language -> get() -> getLang()]['account_disabled'];
  76. $account = Vf_Orm::factory('UserActive') -> find($request -> post('login'));
  77.  
  78. if($account -> isLoaded() && $account -> active == 0)
  79. {
  80. return $this -> set_error($message);
  81. }
  82. }
  83.  
  84.  
  85. if($this -> get_option('check_user'))
  86. {
  87. $message = $this -> error[$this -> language -> get() -> getLang()]['user_exists'];
  88. $user = Vf_Orm::factory('UserExists', $_POST[$this -> get_option('check_user')]);
  89.  
  90. if($user -> isLoaded())
  91. {
  92. return $this -> set_error($message);
  93. }
  94. }
  95.  
  96. return true;
  97. }
  98. }
  99.  
  100. ?>

Blad jest dokladnie tutaj(i w innych miejscach gdzie wywoluje ta metode):
  1. $message = $this -> error[$this -> language -> get() -> getLang()]['banned'];

Klasy zwiazane z tym walidatorem to:
  1. <?php
  2.  
  3. /**
  4. *Volta framework
  5.  
  6. *@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
  7. *@copyright Copyright (c) 2011, marcio
  8. *@version 1.6.5
  9. */
  10.  
  11. require_once(DIR_LIBRARY.'Language.php');
  12.  
  13. abstract class Vf_Validation
  14. {
  15.  
  16. /**
  17. *Skladowa klasy ktora przechowywuje ustawienia walidacji
  18. *@access protected
  19. *@var array $config
  20. */
  21. protected $config = array();
  22.  
  23. /**
  24. *Skladowa klasy ktora przechowywuje instancje klasy Language
  25. *@access protected
  26. *@var object $language
  27. */
  28. protected $language = null;
  29.  
  30.  
  31. /**
  32. *Tworzymy instancje klasy do obslugi jezykow
  33. *@access public
  34. */
  35. public function __construct()
  36. {
  37. $this -> language = new Vf_Language('Validation.php');
  38. }
  39.  
  40.  
  41. /**
  42. *Metoda ustawia konfiguracje
  43. *@access public
  44. *@param array $config
  45. */
  46. public function configure($config)
  47. {
  48. $this -> config = $config;
  49. }
  50.  
  51.  
  52. /**
  53. *Metoda zwraca nam dana wartosc z konfiguracji walidacji
  54. *@access public
  55. *@param string $key
  56. *@return mixed
  57. */
  58. public function get_option($key)
  59. {
  60. return (isset($this -> config[$key])) ? $this -> config[$key] : null;
  61. }
  62.  
  63.  
  64. /**
  65. *Metoda zwraca pelna konfiguracje walidacji
  66. *@access public
  67. *@return array
  68. */
  69. public function get_options()
  70. {
  71. return $this -> config;
  72. }
  73.  
  74.  
  75. /**
  76. *Ustawiamy tresc bledy ustawiajac tez nazwe pola
  77. *@access protected
  78. *@param string tresc bledu
  79. *@param string nazwa pola
  80. *@return string
  81. */
  82. protected function set_error($errorMsg, $fieldname = '')
  83. {
  84. return str_replace('%field%', $fieldname, $errorMsg);
  85. }
  86.  
  87. }
  88. ?>

Potem glowna klasa Vf_Language:
  1. <?php
  2.  
  3. /**
  4. *Volta framework
  5.  
  6. *@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
  7. *@copyright Copyright (c) 2012, marcio
  8. *@version 1.0
  9. */
  10.  
  11. class Vf_Language
  12. {
  13.  
  14. protected $driver = null;
  15.  
  16. protected $extensionsAdapter = array(
  17. 'php' => 'Array',
  18. 'xml' => 'Xml'
  19. );
  20.  
  21. public function __construct($file, $adapter = null)
  22. {
  23. if($adapter === null)
  24. {
  25. $ext = end(explode('.', $file));
  26. $adapter = $this -> extensionsAdapter[sizeof($ext)-1];
  27. }
  28.  
  29. if(Vf_Loader::existsFile(DIR_DRIVERS.'Language/'.$adapter.'.php'))
  30. {
  31. require_once(DIR_DRIVERS.'Language/'.$adapter.'.php');
  32.  
  33. $className = 'Vf_Language_'.$adapter.'_Adapter';
  34.  
  35. if(class_exists($className))
  36. {
  37. $this -> driver = new $className();
  38. $this -> driver -> load($file);
  39. }
  40. }
  41. }
  42.  
  43.  
  44. public function get()
  45. {
  46. return $this -> driver;
  47. }
  48. }
  49.  
  50. ?>

Potem klasa abstrakcyjna language:
  1. <?php
  2.  
  3. /**
  4. *Volta framework
  5.  
  6. *@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
  7. *@copyright Copyright (c) 2012, marcio
  8. *@version 1.0
  9. */
  10.  
  11. abstract class Vf_Language_Abstract
  12. {
  13.  
  14. protected $data = array();
  15.  
  16. protected $lang = null;
  17.  
  18. protected $config = null;
  19.  
  20.  
  21. public function __construct()
  22. {
  23. $this -> config = new Vf_Config('config.Language');
  24. $this -> lang = $this -> config -> default_lang;
  25. }
  26.  
  27.  
  28. public function __get($key)
  29. {
  30. return (isset($this -> data[$this -> getLang()][$key])) ? $this -> data[$this -> getLang()][$key] : null;
  31. }
  32.  
  33.  
  34. public function setLang($lang)
  35. {
  36. $this -> lang = $lang;
  37.  
  38. if(!isset($_SESSION[$this -> config -> session_lang]))
  39. {
  40. $_SESSION[$this -> config -> session_lang] = $lang;
  41. }
  42. else
  43. {
  44. unset($_SESSION[$this -> config -> session_lang]);
  45. $_SESSION[$this -> config -> session_lang] = $lang;
  46. }
  47. }
  48.  
  49.  
  50. public function getLang()
  51. {
  52. if(isset($_SESSION[$this -> config -> session_lang]))
  53. {
  54. return $_SESSION[$this -> config -> session_lang];
  55. }
  56. else
  57. {
  58. return $this -> lang;
  59. }
  60. }
  61.  
  62.  
  63. public function translate($key)
  64. {
  65. return (isset($this -> data[$this -> getLang()][$key])) ? $this -> data[$this -> getLang()][$key] : null;
  66. }
  67.  
  68.  
  69. public function phrase($key, $from, $to, $pluralize = false, $count = null)
  70. {
  71. $ruleCode = $this -> getPluralizationRulesCode($count);
  72.  
  73. if(!$pluralize)
  74. {
  75. $phrase = str_replace($from, $to, $this -> data[$this -> getLang()][$key]);
  76. }
  77. else
  78. {
  79. if(isset($this -> data[$this -> getLang()][$key]['pluralize']))
  80. {
  81. preg_match_all('#\%(.*?)\%#', $this -> data[$this -> getLang()][$key]['text'], $vars);
  82.  
  83. foreach($vars[0] as $var)
  84. {
  85. if(!in_array($var, $from))
  86. {
  87. $replaceVars[] = $var;
  88. $replaceVarsValue[] = $this -> data[$this -> getLang()][$key]['pluralize'][$var][$ruleCode];
  89. }
  90. }
  91.  
  92. $fromPluralize = array_merge($from, $replaceVars);
  93. $toPluralize = array_merge($to, $replaceVarsValue);
  94. $phrase = str_replace($fromPluralize, $toPluralize, $this -> data[$this -> getLang()][$key]['text']);
  95. }
  96. }
  97. return $phrase;
  98. }
  99.  
  100.  
  101. protected function getPluralizationRulesCode($number)
  102. {
  103. switch($this -> getLang())
  104. {
  105. case 'pl':
  106. return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2);
  107.  
  108. case 'de':
  109. case 'es':
  110. case 'it':
  111. case 'en':
  112. return ($number == 1) ? 0 : 1;
  113.  
  114. case 'fr':
  115. return (($number == 0) || ($number == 1)) ? 0 : 1;
  116.  
  117. case 'ro':
  118. return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2);
  119.  
  120. case 'be':
  121. case 'ru':
  122. case 'uk':
  123. return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
  124.  
  125. case 'cs':
  126. case 'sk':
  127. return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2);
  128.  
  129. default:
  130. return 0;
  131. }
  132. }
  133.  
  134.  
  135. abstract public function load($file);
  136. }
  137.  
  138. ?>

i najprostszy "sterownik" dla klasy language opierajacy sie o tablice z php:
  1. <?php
  2.  
  3. /**
  4. *Volta framework
  5.  
  6. *@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
  7. *@copyright Copyright (c) 2012, marcio
  8. *@version 1.0
  9. */
  10.  
  11. require_once(DIR_ABSTRACT.'Language.php');
  12.  
  13. class Vf_Language_Array_Adapter extends Vf_Language_Abstract
  14. {
  15. public function load($file)
  16. {
  17. if(Vf_Loader::existsFile(DIR_LANG.$file))
  18. {
  19. include(DIR_LANG.$file);
  20. $this -> data = $translate;
  21. }
  22. }
  23. }
  24.  
  25. ?>

Bylbym bardzo wdzieczny za jakakolwiek pomoc poniewaz na starym serverze nie mialem bledu i tak w ogole nie wiem dlaczego on jest skoro z metodzie get() w klasie Vf_Language zwracam skladawa driver ktora zawiera klase sterownika.

Albo ja jestem tepy albo php jest tepe byl blad logiczny w metodzie i na starym serverze dzialalo a na nowym juz nie:
  1. public function __construct($file, $adapter = null)
  2. {
  3. if($adapter === null)
  4. {
  5. $ext = end(explode('.', $file));
  6. $adapter = $this -> extensionsAdapter[$ext]; //tutaj byl blad wczesniej bylo $this -> extensionsAdapter[sizeof($ext)-1]
  7. }
  8.  
  9. if(Vf_Loader::existsFile(DIR_DRIVERS.'Language/'.$adapter.'.php'))
  10. {
  11. require_once(DIR_DRIVERS.'Language/'.$adapter.'.php');
  12.  
  13. $className = 'Vf_Language_'.$adapter.'_Adapter';
  14.  
  15. if(class_exists($className))
  16. {
  17. $this -> driver = new $className();
  18. $this -> driver -> load($file);
  19. }
  20. }
  21. }

Moj blad ale skoro dzialalo nawet nie zwrocilem na to uwagi przeciez uzylem end wiec sizeof()-1 jest zbedny, ciekaw jestem jednak dlaczego nie dzialalo na nowym serverze a na starym juz tak....
Pyton_000
Może przez tłumienie błędów działało. Starsza wersja PHP inne interpretacje wyników przez obie wersje. Wariantów jest wiele smile.gif
marcio
Cytat(Pyton_000 @ 25.02.2015, 17:08:42 ) *
Może przez tłumienie błędów działało. Starsza wersja PHP inne interpretacje wyników przez obie wersje. Wariantów jest wiele smile.gif

Zgadzalbym sie z toba gdyby nie fakt ze probowalem na obydwoch serverach identycznej wersji php 5.2.17 i sprawdzilem plik php.ini czy sa jakies wieksze zmiany miedzy jednym i drugim serverem i takich nie bylo wiec problem raczej nie jest w wersjach php(przynajmniej tak mysle) tym bardziej ze mam ustawione wszystkie bledy:
  1. set_exception_handler(array('Exception_Handler', 'Handler'));
  2. set_error_handler(array(new Error_Handler(), 'Handler'));
  3. spl_autoload_register(array('Vf_Loader', 'autoload'));

vokiel
A jak ze ścieżkami do plików, może skrypt czegoś nie znajduje.

Zdebuguj sobie krok po kroku czy obiekt
Kod
$this->language
jest tworzony poprawnie.
marcio
Sciezki byly ok poprostu byl blad logiczny w kodzie:
  1. $adapter = $this -> extensionsAdapter[$ext]; //tutaj byl blad wczesniej bylo $this -> extensionsAdapter[sizeof($ext)-1]

teraz wszystko hula wink.gif

Nie wiem tylko dlaczego na starym serverze dzialal kod z tak trywialnym bledem ktory nie mial prawa dzialac ale nvm to jest php....!
destroyerr
No przecież wiadomo, że to wina php i że testy tego błędu nie wykrywały to też wina php.
marcio
Cytat(destroyerr @ 26.02.2015, 18:25:14 ) *
No przecież wiadomo, że to wina php i że testy tego błędu nie wykrywały to też wina php.

Akurat zadnych testow tdd/bdd nie robilem closedeyes.gif
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-2024 Invision Power Services, Inc.