Mam następujące drzewo katalogów:Kod
public_html
♣ index.php
♣ inc
♥ Language.class.php
♣ install
♥ languages
♦ polish.lang.php
♣ languages
♥ polish
♦ polish.lang.php
♦ settings.lang.php
Zawartość pliku Language.class.php:<?php
final class Language
{
private $lang = null;
private $path = '/languages/';
private $install_path = '/install/languages/';
private $extension = '.lang.php';
public function __construct(string $pack = null, bool $install = false)
{
{
$this->setLanguage($pack, $install);
}
}
public function getLanguages(bool $install = false)
{
try
{
$directoryIterator = new DirectoryIterator($_SERVER['DOCUMENT_ROOT'].$this->path);
$i = 0;
foreach($directoryIterator as $pack)
{
if($pack->isDir() && !$pack->isDot() && !$pack->isLink())
{
$dir = $pack->getFilename();
$settings = $_SERVER['DOCUMENT_ROOT'].$this->path.$dir.'/settings'.$this->extension;
if($install)
{
$file = $_SERVER['DOCUMENT_ROOT'].$this->install_path.$dir.$this->extension;
}
else
{
$file = $_SERVER['DOCUMENT_ROOT'].$this->path.$dir.'/'.$dir.$this->extension;
}
{
require_once($settings);
{
$languages[$i]['name'] = $_LANG['ST_NAME'];
$languages[$i]['pack'] = $dir;
$i++;
}
}
}
}
}
catch(Exception $error)
{
exit($error->getMessage()); }
{
return $languages;
}
}
public function setLanguage(string $pack, bool $install = false)
{
if($install)
{
$file = $_SERVER['DOCUMENT_ROOT'].$this->install_path.$pack.$this->extension;
}
else
{
$file = $_SERVER['DOCUMENT_ROOT'].$this->path.$pack.'/'.$pack.$this->extension;
}
$settings = $_SERVER['DOCUMENT_ROOT'].$this->path.$pack.'/settings'.$this->extension;
{
exit('Warning: "'.$pack.'" language pack doesn\'t exists'); }
require_once($settings);
{
exit('Warning: "'.$pack.'" is not valid language pack'); }
require_once($file);
$this->lang = $_LANG;
}
public function getVariables()
{
{
exit('Warning: No language pack was loaded'); }
return $this->lang;
}
}
?>
Zawartość pliku languages/polish/settings.lang.php:<?php
$_LANG['ST_NAME'] = 'Polski';
$_LANG['ST_CODE'] = 'pl';
$_LANG['ST_DIR'] = 'ltr';
?>
Zawartość pliku languages/polish/polish.lang.php:<?php
$_LANG['POZIOMKI'] = 'Lubie poziomki';
?>
Zawartość pliku install/languages/polish.lang.php:<?php
$_LANG['PLACKI'] = 'Lubie placki';
?>
Zawartość pliku index.php:<?php
require($_SERVER['DOCUMENT_ROOT'].'/inc/Language.class.php');
$language = new Language('polish');
print_r($language->getLanguages()); print_r($language->getLanguages(true)); print_r($language->getVariables()); ?>
A teraz opiszę mój problem. Wywołanie kodu z pliku index.php powinno dać następujący rezultat:Kod
Array
(
[0] => Array
(
[name] => Polski
[pack] => polish
)
)
Array
(
[0] => Array
(
[name] => Polski
[pack] => polish
)
)
Array
(
[ST_NAME] => Polski
[ST_CODE] => pl
[ST_DIR] => ltr
[POZIOMKI] => Lubie poziomki
)
natomiast dostaję tylko to:Kod
Array
(
[ST_NAME] => Polski
[ST_CODE] => pl
[ST_DIR] => ltr
[POZIOMKI] => Lubie poziomki
)
Ma ktoś jakiś pomysł o co chodzi?
Ten post edytował krzywy5830 2.08.2016, 14:17:40