-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added SettingsInspector + ability to settingsTypes via Settings::getM…
…odel() added getModel() text prettify added test for getModel added missing use introduced getModel() and SettingsInspector fixed integer
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 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,48 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelSettings; | ||
|
||
use Spatie\LaravelSettings\Settings; | ||
use ReflectionClass; | ||
use ReflectionProperty; | ||
|
||
class SettingsInspector | ||
{ | ||
public static function getSettingsTypes(array|Settings $settingsClasses): array | ||
{ | ||
$settingsCasts = []; | ||
|
||
if ( $settingsClasses instanceof Settings ) { | ||
$reflection = new ReflectionClass($settingsClasses); | ||
$properties = $reflection->getProperties(ReflectionProperty::IS_PUBLIC); | ||
|
||
foreach ($properties as $property) { | ||
$type = $property->getType(); | ||
$typeName = $type ? $type->getName() : 'mixed'; | ||
|
||
$settingsCasts[$property->getName()] = [ | ||
'type' => $typeName, | ||
'nullable' => $type ? $type->allowsNull() : false, | ||
]; | ||
} | ||
|
||
} elseif ( is_array($settingsClasses) ) { | ||
foreach ($settingsClasses as $group => $settingsClass) { | ||
$reflection = new ReflectionClass($settingsClass); | ||
$properties = $reflection->getProperties(ReflectionProperty::IS_PUBLIC); | ||
|
||
foreach ($properties as $property) { | ||
$type = $property->getType(); | ||
$typeName = $type ? $type->getName() : 'mixed'; | ||
|
||
$settingsCasts[$group][$property->getName()] = [ | ||
'type' => $typeName, | ||
'nullable' => $type ? $type->allowsNull() : false, | ||
]; | ||
} | ||
} | ||
} | ||
|
||
return $settingsCasts; | ||
} | ||
} |
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