1.function:getCollection 增加 排除选项

2.增加 function:getCollections
master
Iwannamaybe 3 years ago
parent a8332f7a8d
commit 322b5c62de

@ -20,7 +20,8 @@
],
"require": {
"php": ">=5.3",
"illuminate/support": "^5.5"
"illuminate/support": "^5.5",
"ext-json": "*"
},
"require-dev": {
"icecave/archer": "dev-develop",

@ -9,8 +9,7 @@ use ReflectionClass;
*
* @api
*/
abstract class AbstractEnumeration extends AbstractValueMultiton implements
EnumerationInterface, \JsonSerializable
abstract class AbstractEnumeration extends AbstractValueMultiton implements EnumerationInterface, \JsonSerializable
{
/**
* Initializes the members of this enumeration based upon its class

@ -11,8 +11,7 @@ use Ifornew\Enum\Exception\UndefinedMemberExceptionInterface;
*
* @api
*/
abstract class AbstractValueMultiton extends AbstractMultiton implements
ValueMultitonInterface
abstract class AbstractValueMultiton extends AbstractMultiton implements ValueMultitonInterface
{
/**
* Returns a single member by value.
@ -123,13 +122,34 @@ abstract class AbstractValueMultiton extends AbstractMultiton implements
/**
* Get the select collections og the enum
*
* @param array $exceptValues
* @return \Illuminate\Support\Collection
*/
final public static function getCollection()
final public static function getCollection(array $exceptValues=[])
{
$collection = new Collection();
foreach (self::members() as $member) {
$collection->put($member->value, $member->description);
if(!in_array($member->value,$exceptValues)){
$collection->put($member->value, $member->description);
}
}
return $collection;
}
/**
* Get the select collections og the enum
*
* @param array $exceptValues
* @return \Illuminate\Support\Collection
*/
final public static function getCollections(array $exceptValues=[])
{
$collection = new Collection();
foreach (self::members() as $member) {
if(!in_array($member->value,$exceptValues)) {
$collection->put(['key' => $member->key, 'value' => $member->value, 'description' => $member->description]);
}
}
return $collection;

@ -7,22 +7,20 @@ use Ifornew\Enum\Commands\MakeEnumCommand;
class EnumServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([
MakeEnumCommand::class,
]);
}
/**
* Perform post-registration booting of services.
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([MakeEnumCommand::class,]);
}
}
/**
* Register any package services.
*/
public function register()
{
}
/**
* Register any package services.
*/
public function register()
{
}
}
Loading…
Cancel
Save