-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ProvinceSeeders registry and interface
- Loading branch information
1 parent
cb2c49b
commit 3a5c6b1
Showing
17 changed files
with
302 additions
and
11 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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Konekt\Address\Contracts; | ||
|
||
interface ProvinceSeeder | ||
{ | ||
public static function getCountryCode(): string; | ||
|
||
/** | ||
* @return array|ProvinceType[] | ||
*/ | ||
public static function getProvinceTypes(): array; | ||
|
||
} |
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
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Konekt\Address\Seeds; | ||
|
||
use Konekt\Address\Contracts\ProvinceType; | ||
use Konekt\Address\Models\ProvinceTypeProxy; | ||
|
||
trait IsProvinceSeeder | ||
{ | ||
public static function getCountryCode(): string | ||
{ | ||
return self::$forCountry; | ||
} | ||
|
||
public static function getProvinceTypes(): array | ||
{ | ||
return array_map(fn(string|ProvinceType $type) => is_string($type) ? ProvinceTypeProxy::create($type): $type, self::$provinceTypes); | ||
} | ||
|
||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Konekt\Address\Seeds; | ||
|
||
use InvalidArgumentException; | ||
use Illuminate\Support\Str; | ||
use Konekt\Address\Contracts\ProvinceSeeder; | ||
use Konekt\Extend\Concerns\HasRegistry; | ||
use Konekt\Extend\Concerns\RequiresClassOrInterface; | ||
use Konekt\Extend\Contracts\Registry; | ||
|
||
class ProvinceSeeders implements Registry | ||
{ | ||
use HasRegistry; | ||
use RequiresClassOrInterface; | ||
|
||
protected static string $requiredInterface = ProvinceSeeder::class; | ||
|
||
public static function make(string $id, array $parameters = []): object | ||
{ | ||
if (null === $class = self::getClassOf($id)) { | ||
throw new InvalidArgumentException( | ||
"No type is registered with the id `$id`." | ||
); | ||
} | ||
|
||
return app()->make($class, $parameters); | ||
} | ||
|
||
/** @return ProvinceSeeder[] */ | ||
public static function availableSeedersOfCountry(string $country): array | ||
{ | ||
return array_filter(self::$registry, fn($class) => $class::getCountryCode() === $country); | ||
} | ||
|
||
public static function extend(string $seederClass): void | ||
{ | ||
self::add(self::generateId($seederClass), $seederClass); | ||
} | ||
|
||
private static function generateId(string $class): string | ||
{ | ||
return Str::snake(class_basename($class)); | ||
} | ||
} |
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
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
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
Oops, something went wrong.