-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5616cf2
commit 086d606
Showing
4 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace IsapOu\EnumHelpers\Concerns; | ||
|
||
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Support\Str; | ||
|
||
use function get_class; | ||
use function rtrim; | ||
use function trans; | ||
|
||
trait HasLabel | ||
{ | ||
public function getLabel(?string $prefix = null, ?string $namespace = null): string | ||
{ | ||
if (empty($prefix)) { | ||
$prefix = $this->getPrefix(); | ||
} | ||
if (empty($namespace)) { | ||
$namespace = $this->getNamespace(); | ||
} | ||
|
||
if (! empty($prefix)) { | ||
$prefix = rtrim($prefix, '.') . '.'; | ||
} | ||
if (! empty($namespace) && ! Str::endsWith($namespace, '::')) { | ||
$namespace .= '::'; | ||
} | ||
|
||
return trans(vsprintf('%s%s%s.%s', [$namespace, $prefix, get_class($this), $this->name])); | ||
} | ||
|
||
protected function getPrefix(): ?string | ||
{ | ||
return Config::get('enum-helpers.label.prefix'); | ||
} | ||
|
||
protected function getNamespace(): ?string | ||
{ | ||
return Config::get('enum-helpers.label.namespace'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace IsapOu\EnumHelpers\Contracts; | ||
|
||
interface HasLabel | ||
{ | ||
public function getLabel(): ?string; | ||
} |