I have a class called "Language" on my project im working on which lets you choose a language the page is on and determines which language is currently chosen. I was updating my laravel and ran into a problem on the 5.0 update that it no longer finds my Language class. I think it is an autoloader issue but i am not 100% sure about it.
Language.php is the class that cant be found and the file that cant find it is home.php under "resources\views\home.php"
This is my Language.php file
<?php
namespace App\Libaries;
use Illuminate\Support\Facades\Facade;
class Language extends Facade
{
private static $primary;
private static $secondary;
protected static function getFacadeAccessor() { return 'Language'; }
public static function init()
{
if (strlen(Request::segment(1)) === 2) {
self::$primary = Request::segment(1);
} elseif (strlen(Request::segment(1)) !== 2) {
self::$primary = 'fi';
}
if (self::$primary === 'ee' || self::$primary === 'en') {
self::$secondary = 'fi';
} elseif (self::$primary !== 'en' && self::$primary !== 'ee') {
self::$secondary = 'en';
}
}
public static function getsecondary()
{
return self::$secondary;
}
public static function getprimary()
{
return self::$primary;
}
public static function getAllLanguages()
{
return array(
'fi' => 'Suomeksi',
'en' => 'In English',
'se' => 'På Svenska',
'de' => 'Deutsch',
'ru' => 'по-русски',
'ee' => 'Eesti keeles',
'pl' => 'Po Polsku',
'fr' => 'En Français',
'es' => 'En Español',
'cn' => '中文',
'cs' => 'Čeština',
'sk' => 'Slovenčina',
'nl' => 'Nederlands',
'jp' => 'Japanese',
);
}
public static function line($key)
{
if (Lang::has($key, self::$primary) === false) {
return mbUcfirst(Lang::get($key, array(), self::$secondary));
}
return mbUcfirst(Lang::get($key, array(), self::$primary));
}
}
function mbUcfirst($string)
{
return mb_strtoupper(mb_substr($string, 0, 1))
. mb_substr($string, 1);
}
This is my home.php file
<?php
namespace App\resources\views;
use App\Libraries\Language
?>
<h1><?=Language::line('common.index')?></h1>
<div id="home-description-text">
<?=Page::getPage('index')?>
</div>
<div id="home-description">
<a href="<?=$language?>/project">
<span id="home-description-title"><?=Language::line('home.description_link_label')?></span>
</a>
</div>
<div id="home-history">
<a href="<?=$language?>/history">
<img id="home-history-image" src="/img/home/history.jpg" alt="history" />
<span id="home-history-title"><?=Language::line('home.history_link_label')?></span>
</a>
</div>
<div id="home-map">
<a href="<?=$language?>/map">
<img id="home-map-image" src="/img/home/map.jpg" alt="map" />
<span id="home-map-title"><?=Language::line('home.map_link_label')?></span>
</a>
</div>
<div id="home-destinations">
<a href="<?=$language?>/buildings">
<img id="home-destinations-image" src="/img/home/destinations.jpg" alt="destinations" />
<span id="home-destinations-title"><?=Language::line('home.destinations_link_label')?></span>
</a>
</div>
<div id="home-ebook">
<a href="<?=$language?>/ebook">
<img id="home-ebook-image" src="/img/home/ebook.jpg" alt="ebook" />
<span id="home-ebook-title"><?=Language::line('home.ebook_link_label')?></span>
</a>
</div>
<div class="clear-both">
</div>
This is my composer.json file
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database/migrations",
"database/seeds",
"app/Http/Controllers",
"app/Libraries/Language.php",
"app/models",
"app/commands",
"resources/views",
"resources/lang",
"vendor/laravel/framework/src/Illuminate/Contracts/View"
],
"psr-4": {
"App\\": "vv5/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Sorry in advance if the formatting is bad this is my first time posting to stack overflow.
I am still new to namespaces so im sure there might be an obvious thing im missing but i cant seem to figure it out on my own. Hopefully this post will help, thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire