Blad po przenosieniu bloga na inny server

0

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:

<?php 

/**
*Volta framework

*@author marcio <[email protected]>, <[email protected]>
*@copyright Copyright (c) 2012, marcio
*@version 1.0
*/

require_once(DIR_ABSTRACT.'Validation.php');
require_once(DIR_INTERFACES.'IValidation.php');

class user extends Vf_Validation implements IValidation
{

	/**
	*Skladowa klasy ktora przechowywuje tresci bledow
	*@access protected
	*/
	protected $error = array(
							'pl' => array(
									'banned' => 'To konto zostalo zbanowane',
									'account_disabled' => 'To konto nie zostalo aktywowane',
									'user_exists' => 'Uzytkownik o takiej nazwie juz istnieje'
										)		
							);
	
	
	/**
	*Konstruktor ustawia konfiguracje walidatora
	*@access public 
	*@param array $cfg
	*/
	public function __construct($cfg)
	{
		parent::__construct();
		$this -> configure($cfg);
	}
	
	
	/**
	*Metoda ktora sprawdza walidacje danych na podstawie wczesniej ustawionej konfiguracji
	*@access public 
	*@param string $object tresc do walidacji
	*@return bool|string
	*/
	public function is_valid($object)
	{	
		if($this -> get_option('check_ban'))
		{
			if(empty($object))
			{
				return true;
			}
			
			$message = $this -> error[$this -> language -> get() -> getLang()]['banned']; //tutaj jest blad
			$ban = Vf_Orm::factory('Ban');
			
			if($ban -> isBanned($object))
			{
				return $this -> set_error($message);
			}
		}
		
		
		if($this -> get_option('check_is_active'))
		{
			$request = new Vf_Request();
			if(empty($object))
			{
				return true;
			}
			
			$message = $this -> error[$this -> language -> get() -> getLang()]['account_disabled'];
			$account = Vf_Orm::factory('UserActive') -> find($request -> post('login'));
			
			if($account -> isLoaded() && $account -> active == 0)
			{
				return $this -> set_error($message);
			}
		}
		
		
		if($this -> get_option('check_user'))
		{
			$message = $this -> error[$this -> language -> get() -> getLang()]['user_exists'];
			$user = Vf_Orm::factory('UserExists', $_POST[$this -> get_option('check_user')]);
			
			if($user -> isLoaded())
			{
				return $this -> set_error($message);
			}
		}
		
		return true;
	}
}

?>

Blad jest dokladnie tutaj(i w innych miejscach gdzie wywoluje ta metode):

$message = $this -> error[$this -> language -> get() -> getLang()]['banned'];

Klasy zwiazane z tym walidatorem to:

<?php 

/**
*Volta framework

*@author marcio <[email protected]>, <[email protected]>
*@copyright Copyright (c) 2011, marcio
*@version 1.6.5
*/

require_once(DIR_LIBRARY.'Language.php');

abstract class Vf_Validation
{

	/**
	*Skladowa klasy ktora przechowywuje ustawienia walidacji
	*@access protected
	*@var array $config
	*/
	protected $config = array();

	/**
	*Skladowa klasy ktora przechowywuje instancje klasy Language
	*@access protected
	*@var object $language
	*/
	protected $language = null;
	
	
	/**
	*Tworzymy instancje klasy do obslugi jezykow
	*@access public 
	*/
	public function __construct()
	{
		$this -> language = new Vf_Language('Validation.php');
	}

	
	/**
	*Metoda ustawia konfiguracje
	*@access public 
	*@param array $config
	*/
	public function configure($config)
	{
		$this -> config = $config;
	}
	
	
	/**
	*Metoda zwraca nam dana wartosc z konfiguracji walidacji
	*@access public 
	*@param string $key
	*@return mixed 
	*/
	public function get_option($key)
	{
		return (isset($this -> config[$key])) ? $this -> config[$key] : null;
	}
	
	
	/**
	*Metoda zwraca pelna konfiguracje walidacji
	*@access public 
	*@return array
	*/
	public function get_options()
	{
		return $this -> config;
	}
	
	
	/**
	*Ustawiamy tresc bledy ustawiajac tez nazwe pola
	*@access protected
	*@param string tresc bledu
	*@param string nazwa pola
	*@return string
	*/
	protected function set_error($errorMsg, $fieldname = '') 
	{
		return str_replace('%field%', $fieldname, $errorMsg);
	}
	
}
?>

Potem glowna klasa Vf_Language:

<?php

/**
*Volta framework

*@author marcio <[email protected]>, <[email protected]>
*@copyright Copyright (c) 2012, marcio
*@version 1.0
*/

class Vf_Language
{

	protected $driver = null;
	
	protected $extensionsAdapter = array(
										'php' => 'Array',
										'xml' => 'Xml'
										);
	
	public function __construct($file, $adapter = null)
	{
		if($adapter === null)
		{
			$ext = end(explode('.', $file));
			$adapter = $this -> extensionsAdapter[sizeof($ext)-1];
		}
		
		if(Vf_Loader::existsFile(DIR_DRIVERS.'Language/'.$adapter.'.php'))
		{
			require_once(DIR_DRIVERS.'Language/'.$adapter.'.php');
			
			$className = 'Vf_Language_'.$adapter.'_Adapter';
	
			if(class_exists($className))
			{
				$this -> driver = new $className();
				$this -> driver -> load($file);
			}
		}
	}
	
	
	public function get()
	{
		return $this -> driver;
	}
}

?>

Potem klasa abstrakcyjna language:

<?php

/**
*Volta framework

*@author marcio <[email protected]>, <[email protected]>
*@copyright Copyright (c) 2012, marcio
*@version 1.0
*/

abstract class Vf_Language_Abstract
{

	protected $data = array();
	
	protected $lang = null;
	
	protected $config = null;
	
	
	public function __construct()
	{	
		$this -> config = new Vf_Config('config.Language');
		$this -> lang = $this -> config -> default_lang;
	}
	
	
	public function __get($key)
	{
		return (isset($this -> data[$this -> getLang()][$key])) ? $this -> data[$this -> getLang()][$key] : null;
	}
	
	
	public function setLang($lang)
	{
		$this -> lang = $lang;
		
		if(!isset($_SESSION[$this -> config -> session_lang]))
		{
			$_SESSION[$this -> config -> session_lang] = $lang;
		}
		else
		{
			unset($_SESSION[$this -> config -> session_lang]);
			$_SESSION[$this -> config -> session_lang] = $lang;
		}
	}
	
	
	public function getLang()
	{
		if(isset($_SESSION[$this -> config -> session_lang]))
		{
			return $_SESSION[$this -> config -> session_lang];
		}
		else
		{
			return $this -> lang;
		}
	}
	
	
	public function translate($key)
	{
		return (isset($this -> data[$this -> getLang()][$key])) ? $this -> data[$this -> getLang()][$key] : null;
	}

	
	public function phrase($key, $from, $to, $pluralize = false, $count = null)
	{
		$ruleCode = $this -> getPluralizationRulesCode($count);

		if(!$pluralize)
		{
			$phrase = str_replace($from, $to, $this -> data[$this -> getLang()][$key]);
		}
		else
		{
			if(isset($this -> data[$this -> getLang()][$key]['pluralize']))
			{
				preg_match_all('#\%(.*?)\%#', $this -> data[$this -> getLang()][$key]['text'], $vars);
				
				foreach($vars[0] as $var)
				{
					if(!in_array($var, $from))
					{
						$replaceVars[] = $var;
						$replaceVarsValue[] = $this -> data[$this -> getLang()][$key]['pluralize'][$var][$ruleCode];
					}
				}
				
				$fromPluralize = array_merge($from, $replaceVars);
				$toPluralize = array_merge($to, $replaceVarsValue);
				$phrase = str_replace($fromPluralize, $toPluralize, $this -> data[$this -> getLang()][$key]['text']);
			}
		}
		return $phrase;
	}
	
	
	protected function getPluralizationRulesCode($number)
	{
		switch($this -> getLang())
		{
			case 'pl':
					return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2);
				
			case 'de':
			case 'es':
			case 'it':
			case 'en':
					return ($number == 1) ? 0 : 1;
					
			case 'fr':
					return (($number == 0) || ($number == 1)) ? 0 : 1;
					
			case 'ro':
					return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2);
					
			case 'be':
			case 'ru':
	        case 'uk':
					return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
					
			case 'cs':
            case 'sk':
	                return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2);
					
			default:
					return 0;
		}
	}
	
	
	abstract public function load($file);
}

?>

i najprostszy "sterownik" dla klasy language opierajacy sie o tablice z php:

<?php

/**
*Volta framework

*@author marcio <[email protected]>, <[email protected]>
*@copyright Copyright (c) 2012, marcio
*@version 1.0
*/

require_once(DIR_ABSTRACT.'Language.php');

class Vf_Language_Array_Adapter extends Vf_Language_Abstract
{
	public function load($file)
	{
		if(Vf_Loader::existsFile(DIR_LANG.$file))
		{
			include(DIR_LANG.$file);
			$this -> data = $translate;
		}
	}
}

?>

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.

1

A może treść błędu chociaż? Najważniejszego nie dałeś...

0
dzek69 napisał(a):

A może treść błędu chociaż? Najważniejszego nie dałeś...

o kurde ale ze mnie dupa haha sry:

Call to a member function getLang() on a non-object in

0

Z tego co przeanalizowałem - skrypt prawdopodobnie nie widzi pliku z tłumaczeniami - choć dziwnie się to objawia, powinien się wywalić już wcześniej.

Dopisz sobie przed problematyczną linijką to:

echo "<pre>";
var_dump($this -> language);
echo PHP_EOL;
var_dump($this -> language -> get());
echo "</pre>";
die();

i wklej wynik.

0
dzek69 napisał(a):

Z tego co przeanalizowałem - skrypt prawdopodobnie nie widzi pliku z tłumaczeniami - choć dziwnie się to objawia, powinien się wywalić już wcześniej.

Dopisz sobie przed problematyczną linijką to:

echo "<pre>";
var_dump($this -> language);
echo PHP_EOL;
var_dump($this -> language -> get());
echo "</pre>";
die();

i wklej wynik.

Plik znajduje sie w i18n/Validation.php i ma taka zawartosc:

 
<?php 

//PL

$translate['pl']['required'] = 'Pole %field% nie moze byc puste';
$translate['pl']['MinLenght'] = 'Pole %field% jest zakrotkie';
$translate['pl']['MaxLenght'] = 'Pole %field% jest zadlugie';
$translate['pl']['Between'] = 'Pole %field% nie miesci sie w zakresie dlugosci';
$translate['pl']['Email'] = 'Pole %field% nie jest poprawnym adresem email';
$translate['pl']['Ip'] = 'Pole %field% nie jest poprawnym adresem IP';
$translate['pl']['Regexp'] = 'Pole %field% jest niepoprawne';
$translate['pl']['Alpha'] = 'Pole %field% moze zawierac tylko litery';
$translate['pl']['Digit'] = 'Pole %field% moze zawierac tylko liczby';
$translate['pl']['AlphaDigit'] = 'Pole %field% moze zawierac tylko znaki alfanumeryczne';
$translate['pl']['Range'] = 'Pole %field% nie miesci sie w podanym zakresie znakow';
$translate['pl']['Type'] = 'Pole %field% nie jest zadanym typem';

//ENG

$translate['eng']['required'] = 'Field %field% is required';
$translate['eng']['MinLenght'] = 'Field %field% is too short';
$translate['eng']['MaxLenght'] = 'Field %field% is too long';
$translate['eng']['Between'] = 'Field %field% is too long or short';
$translate['eng']['Email'] = 'Field %field% isn\'t valid email adress';
$translate['eng']['Ip'] = 'Field %field% isn\t valid ip adress';
$translate['eng']['Regexp'] = 'Field %field% is wrong';
$translate['eng']['Alpha'] = 'Field %field% has got only letters';
$translate['eng']['Digit'] = 'Field %field% has got only numbers';
$translate['eng']['AlphaDigit'] = 'Field %field% has got only alpha-digit letters';
$translate['eng']['Range'] = 'Field %field% isn\'t right for the pattern';
$translate['eng']['Type'] = 'Filed %field% ins\t right type';

return $translate;
?>

Ogolnie zrobilem var_dump i mam:

 
object(Vf_Language)#39 (2) { ["driver":protected]=> NULL ["extensionsAdapter":protected]=> array(2) { ["php"]=> string(5) "Array" ["xml"]=> string(3) "Xml" } } NULL

Czyli objekt Vf_language sie inicjuje ale nie wczytuje adaptera Vf_Language_Array_Adapter do skladowej driver...
Na drugim serverze var_dump daje mi:

object(Vf_Language)#44 (2) { ["driver:protected"]=> object(Vf_Language_Array_Adapter)#43 (3) { ["data:protected"]=> array(2) { ["pl"]=> array(12) { ["required"]=> string(31) "Pole %field% nie moze byc puste" ["MinLenght"]=> string(27) "Pole %field% jest zakrotkie" ["MaxLenght"]=> string(26) "Pole %field% jest zadlugie" ["Between"]=> string(47) "Pole %field% nie miesci sie w zakresie dlugosci" ["Email"]=> string(45) "Pole %field% nie jest poprawnym adresem email" ["Ip"]=> string(42) "Pole %field% nie jest poprawnym adresem IP" ["Regexp"]=> string(29) "Pole %field% jest niepoprawne" ["Alpha"]=> string(39) "Pole %field% moze zawierac tylko litery" ["Digit"]=> string(39) "Pole %field% moze zawierac tylko liczby" ["AlphaDigit"]=> string(53) "Pole %field% moze zawierac tylko znaki alfanumeryczne" ["Range"]=> string(53) "Pole %field% nie miesci sie w podanym zakresie znakow" ["Type"]=> string(35) "Pole %field% nie jest zadanym typem" } ["eng"]=> array(12) { ["required"]=> string(25) "Field %field% is required" ["MinLenght"]=> string(26) "Field %field% is too short" ["MaxLenght"]=> string(25) "Field %field% is too long" ["Between"]=> string(34) "Field %field% is too long or short" ["Email"]=> string(38) "Field %field% isn't valid email adress" ["Ip"]=> string(35) "Field %field% isn\t valid ip adress" ["Regexp"]=> string(22) "Field %field% is wrong" ["Alpha"]=> string(34) "Field %field% has got only letters" ["Digit"]=> string(34) "Field %field% has got only numbers" ["AlphaDigit"]=> string(46) "Field %field% has got only alpha-digit letters" ["Range"]=> string(41) "Field %field% isn't right for the pattern" ["Type"]=> string(30) "Filed %field% ins\t right type" } } ["lang:protected"]=> string(2) "pl" ["config:protected"]=> object(Vf_Config)#46 (3) { ["defaultConfigLoaderAdapter:protected"]=> string(5) "Array" ["config:protected"]=> array(2) { ["default_lang"]=> string(2) "pl" ["session_lang"]=> string(4) "lang" } ["accepted:protected"]=> array(5) { ["Array"]=> string(3) "php" ["Ini"]=> string(3) "ini" ["Csv"]=> string(3) "csv" ["Xml"]=> string(3) "xml" ["Json"]=> string(4) "json" } } } ["extensionsAdapter:protected"]=> array(2) { ["php"]=> string(5) "Array" ["xml"]=> string(3) "Xml" } } object(Vf_Language_Array_Adapter)#43 (3) { ["data:protected"]=> array(2) { ["pl"]=> array(12) { ["required"]=> string(31) "Pole %field% nie moze byc puste" ["MinLenght"]=> string(27) "Pole %field% jest zakrotkie" ["MaxLenght"]=> string(26) "Pole %field% jest zadlugie" ["Between"]=> string(47) "Pole %field% nie miesci sie w zakresie dlugosci" ["Email"]=> string(45) "Pole %field% nie jest poprawnym adresem email" ["Ip"]=> string(42) "Pole %field% nie jest poprawnym adresem IP" ["Regexp"]=> string(29) "Pole %field% jest niepoprawne" ["Alpha"]=> string(39) "Pole %field% moze zawierac tylko litery" ["Digit"]=> string(39) "Pole %field% moze zawierac tylko liczby" ["AlphaDigit"]=> string(53) "Pole %field% moze zawierac tylko znaki alfanumeryczne" ["Range"]=> string(53) "Pole %field% nie miesci sie w podanym zakresie znakow" ["Type"]=> string(35) "Pole %field% nie jest zadanym typem" } ["eng"]=> array(12) { ["required"]=> string(25) "Field %field% is required" ["MinLenght"]=> string(26) "Field %field% is too short" ["MaxLenght"]=> string(25) "Field %field% is too long" ["Between"]=> string(34) "Field %field% is too long or short" ["Email"]=> string(38) "Field %field% isn't valid email adress" ["Ip"]=> string(35) "Field %field% isn\t valid ip adress" ["Regexp"]=> string(22) "Field %field% is wrong" ["Alpha"]=> string(34) "Field %field% has got only letters" ["Digit"]=> string(34) "Field %field% has got only numbers" ["AlphaDigit"]=> string(46) "Field %field% has got only alpha-digit letters" ["Range"]=> string(41) "Field %field% isn't right for the pattern" ["Type"]=> string(30) "Filed %field% ins\t right type" } } ["lang:protected"]=> string(2) "pl" ["config:protected"]=> object(Vf_Config)#46 (3) { ["defaultConfigLoaderAdapter:protected"]=> string(5) "Array" ["config:protected"]=> array(2) { ["default_lang"]=> string(2) "pl" ["session_lang"]=> string(4) "lang" } ["accepted:protected"]=> array(5) { ["Array"]=> string(3) "php" ["Ini"]=> string(3) "ini" ["Csv"]=> string(3) "csv" ["Xml"]=> string(3) "xml" ["Json"]=> string(4) "json" } } }
 

i jak widac obiekt laduje sie dobrze....

0

Albo ja jestem tepy albo php jest tepe byl blad logiczny w metodzie i na starym serverze dzialalo a na nowym juz nie:

	public function __construct($file, $adapter = null)
	{
		if($adapter === null)
		{
			$ext = end(explode('.', $file));
			$adapter = $this -> extensionsAdapter[$ext]; //tutaj byl blad wczesniej bylo $this -> extensionsAdapter[sizeof($ext)-1]
		}

		if(Vf_Loader::existsFile(DIR_DRIVERS.'Language/'.$adapter.'.php'))
		{
			require_once(DIR_DRIVERS.'Language/'.$adapter.'.php');
			
			$className = 'Vf_Language_'.$adapter.'_Adapter';
	
			if(class_exists($className))
			{
				$this -> driver = new $className();
				$this -> driver -> load($file);
			}
		}
	}

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

0

sprawdź sobie na obu serwerach jaka wartość się z tego obliczała (czyli na obu wstaw sobie var_dump-y z wartości):
sizeof($ext)-1,
$ext,
$this -> extensionsAdapter[sizeof($ext)-1],
$this -> extensionsAdapter[$ext]

można też zbadać samo $file i wynik z explode - żeby się dowiedzieć czy faktycznie problemem jest któraś z tych linijek, a może już wcześniej w kodzie coś jest nie tak

0

Kod zdebugowalem i blad byl tutaj:

$this -> extensionsAdapter[sizeof($ext)-1]
 

Niepotrzebnie uzylem sizeof()-1 skoro uzywam end przy explode nie wiem jak to w ogole moglo dzialac na starym srv ale nvm to jest php wiec tutaj wszystko jest mozliwe

1 użytkowników online, w tym zalogowanych: 0, gości: 1