protected function makeSource() { if (empty($this->source)) { $locale = $this->locale; $format = $this->format; $path = $this->path; $this->source = Source::create(compact('locale', 'format', 'path')); } return $this; }
/** * Execute the console command. * * @return mixed */ public function handle() { $source = Source::find($this->argument('source')); $path = $this->argument('path'); $format = $source->format; $locale = $source->locale; $loader = Factory::make($format, $locale); $loader->setSource($source); $output = $loader->read($path); dd($output); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('sources')->delete(); DB::table('strings')->delete(); $source = ['locale' => 'en', 'format' => 'twine', 'path' => null]; $source = Source::create($source); $strings = ['save' => 'Save', 'load' => 'Load', 'new' => 'New', 'open' => 'Open', 'close' => 'Close', 'ok' => 'OK', 'cancel' => 'Cancel', 'delete' => 'Delete']; foreach ($strings as $key => $value) { $string = ['key' => $key, 'uri' => 'basic.' . $key, 'value' => $value, 'locale' => 'en', 'source_id' => $source->id]; $string = String::create($string); } }
/** * Bootstrap any application services. * * @return void */ public function boot() { $user = Auth::user() ?: User::whereEmail('system@twine')->first(); Repository::creating(function ($model) use($user) { $model->created_by = $user->id; }); Project::creating(function ($model) use($user) { $model->created_by = $user->id; }); String::creating(function ($model) use($user) { $model->created_by = $user->id; }); Source::creating(function ($model) use($user) { $model->created_by = $user->id; }); }
private function processProject($name, $url) { $project_id = $this->model->id; $path = explode('.', str_replace($this->model->name_branch . '.', '', $name)); $path = array_filter($path, function ($val) { return !in_array($val, [$this->model->name, $this->model->name . '-properties', $this->model->branch, 'master', 'properties']); }); $path = implode('.', $path); $format = pathinfo($path, PATHINFO_EXTENSION); $locale = pathinfo($path, PATHINFO_FILENAME); if ($locale && $format) { $source = Source::firstOrCreate(compact('name', 'locale', 'format', 'url', 'project_id')); } else { $source = false; } return $source; }