Skip to content

Commit

Permalink
only load repository when model exists
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnolivier committed Mar 17, 2017
1 parent 5bd9845 commit 517af9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public function __construct(LoaderInterface $loader, $locale)
private function initializeDependencies()
{
try {
if(! class_exists('\Anomaly\Streams\Platform\Model\Translations\TranslationsTranslationsEntryModel')) {
throw new \Exception("TranslationsTranslationsEntryModel has not been compiled yet. Execute php artisan streams:compile");
}

$this->moduleTranslationsRepo = app(ModuleTranslationsRepository::class);
} catch(\Exception $e) {
// this might happen when streams:compile hasn't been executed yet
Expand All @@ -30,6 +34,12 @@ private function initializeDependencies()
public function get($key, array $replace = [], $locale = null, $fallback = true)
{
try {

// fallback to default behaviour if the translations model hasn't been compiled yet
if(! class_exists('\Anomaly\Streams\Platform\Model\Translations\TranslationsTranslationsEntryModel')) {
return parent::get($key, $replace, $locale, $fallback);
}

if (empty($locale)) {
$locale = app()->getLocale();
}
Expand Down
1 change: 0 additions & 1 deletion src/Translator/TranslatorServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Bitsoflove\TranslationsModule\Translator;

use Bitsoflove\TranslationsModule\TranslationsModule;
use Bitsoflove\TranslationsModule\Translator\Translator as BolTranslator;
use Illuminate\Support\Facades\Log;
use Illuminate\Translation\TranslationServiceProvider;
Expand Down

0 comments on commit 517af9d

Please sign in to comment.