File: D:/HostingSpaces/SBogers10/honger.komma.pro/app/KommaApp/Kms/Core/Kms.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Kms\Core;
use App\KommaApp\Sites\SiteService;
use Illuminate\Routing\Router;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Lang;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Languages\Models\SiteLanguage;
use App\KommaApp\Sites\Kms\SitesRepository;
use App\KommaApp\Sites\Models\Site;
class Kms implements KmsInterface
{
protected $siteService;
protected $site;
protected $sites;
protected $siteLanguages = [];
protected $sitesIndex = [];
protected $siteLanguageIdIndex;
protected $siteLanguageIndex;
function __construct(SiteService $siteService)
{
// Get all sites
$this->siteService = $siteService;
$this->sites = $this->siteService->getSites();
}
/**
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function getSites(): Collection
{
return $this->sites;
}
/**
* @param $siteSlug
*/
public function setSite(string $siteSlug)
{
$this->site = $this->sites->where('slug', $siteSlug)->first();
}
/**
* @return Site
*/
public function getSite()
{
if ($this->site) {
return $this->site;
}
return null;
}
/**
* @return int
*/
public function getSiteId()
{
if ($this->site) {
return $this->site->id;
}
return null;
}
/**
* @return int
*/
public function getSiteDefaultLanguage(): int
{
if ($this->site) {
return $this->site->default_language_id;
}
return 104;
}
/**
* @return string
*/
public function getSiteSlug()
{
if ($this->site) {
return $this->site->slug;
}
return null;
}
/**
* Returns the current site's languages
*
* @return Collection of Language
*/
public function getSiteLanguages(): Collection
{
if ($this->site) {
return $this->site->languages;
}
$defaultSiteLanguage = $this->getSiteDefaultLanguage();
if($defaultSiteLanguage)
{
$language = Language::find($defaultSiteLanguage);
if($language) return new Collection([$language]);
}
return collect();
}
/**
* Gets a class name (with or without namespace) and returns the class name only without the namespace
*
* @param object|string $classInstanceOrReference
* @param bool $snakecase If true then the shortModelClassName will be formatted to snake_case.
* @param bool $removeModelString Wether or not to remove the string 'model' if it is in the class name
* @return string
*/
public function getShortNameFromClass($classInstanceOrReference, bool $snakecase = false, bool $removeModelString = false): string
{
if(!is_object($classInstanceOrReference) && !is_string($classInstanceOrReference)) throw new \InvalidArgumentException("Argument 1 passed to this method must be an class instance. But was a: ".gettype($classInstanceOrReference));
$FQCNSplit = (is_object($classInstanceOrReference)) ? explode('\\', get_class($classInstanceOrReference)) : explode('\\', $classInstanceOrReference);
if($FQCNSplit == $classInstanceOrReference) return $classInstanceOrReference;
$shortModelClassName = $FQCNSplit[count($FQCNSplit)-1];
if($snakecase) return snake_case($shortModelClassName);
return $shortModelClassName;
}
}