diff --git a/composer.json b/composer.json index 2fa2ff5..eb41c85 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,14 @@ "require": { "statamic/cms": "^3.0" }, + "authors": [ + { + "name": "Steven Peercy" + } + ], + "support": { + "email": "steven@pttrn.co" + }, "autoload": { "psr-4": { "Pattern\\Silhouette\\": "src" @@ -14,7 +22,7 @@ "extra": { "statamic": { "name": "Silhouette", - "description": "Dynamic user data for your static sites." + "description": "Dynamic user data for your static or cached sites." }, "laravel": { "providers": [ diff --git a/config/silhouette.php b/config/silhouette.php deleted file mode 100644 index f4a8a24..0000000 --- a/config/silhouette.php +++ /dev/null @@ -1,5 +0,0 @@ - env('SILHOUETTE_ELOQUENT_MODEL') -]; diff --git a/src/Http/Controllers/SilhouetteController.php b/src/Http/Controllers/SilhouetteController.php index fee5195..9297c2b 100644 --- a/src/Http/Controllers/SilhouetteController.php +++ b/src/Http/Controllers/SilhouetteController.php @@ -2,42 +2,26 @@ namespace Pattern\Silhouette\Http\Controllers; -use Illuminate\Http\Request; -use Statamic\Auth\Eloquent\User as StatamicUser; use Statamic\Http\Controllers\Controller; class SilhouetteController extends Controller { - protected $methods; - protected $user; - - public function __construct() + public function __invoke() { - $this->middleware(function ($request, $next) { - $this->user = auth()->user() && config('silhouette.model') - ? StatamicUser::fromModel(auth()->user()) - : auth()->user(); - - return $next($request); - }); - - $this->methods = [ - 'email', - 'initials' - ]; - } - - public function __invoke(Request $request) - { - if ($this->user) { + if (auth()->check()) { return response() ->json( collect( - explode(',', $request->input('attributes')) + explode(',', request('attributes')) )->flatMap(function ($attribute) { + $isMethod = false; + if (substr($attribute, -2) == '()') { + $attribute = substr($attribute, 0, -2); + $isMethod = true; + } if ($attribute != 'password') { return [ - $attribute => $this->getAttribute($attribute) + $attribute => $this->getAttribute($attribute, $isMethod) ]; } }) @@ -47,11 +31,11 @@ public function __invoke(Request $request) return response()->json(false); } - private function getAttribute($attribute) + private function getAttribute($attribute, $isMethod) { - if (in_array($attribute, $this->methods)) { - return $this->user->{$attribute}(); + if ($isMethod) { + return auth()->user()->{$attribute}(); } - return $this->user->value($attribute); + return auth()->user()->{$attribute}; } } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 4bff375..7830d90 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -2,6 +2,7 @@ namespace Pattern\Silhouette; +use Pattern\Silhouette\Tags\SilhouetteTag; use Statamic\Providers\AddonServiceProvider; class ServiceProvider extends AddonServiceProvider @@ -11,7 +12,7 @@ class ServiceProvider extends AddonServiceProvider ]; protected $tags = [ - \Pattern\Silhouette\Tags\SilhouetteTag::class, + SilhouetteTag::class, ]; public function boot() diff --git a/src/Tags/SilhouetteTag.php b/src/Tags/SilhouetteTag.php index 47403f0..e2ee7ef 100644 --- a/src/Tags/SilhouetteTag.php +++ b/src/Tags/SilhouetteTag.php @@ -8,51 +8,39 @@ class SilhouetteTag extends Tags { protected static $handle = 'silhouette'; + protected $attributes = 'name,email,avatar,initials'; + public function index() { - $attributes = $this->params->get('attributes') ?? 'name,email,avatar,initials'; - $openingTag = '
params->get('attributes') ?? $this->attributes; + $open = '
'; - $closingTag = '
'; + $close = '
'; - return $openingTag . $this->content . $closingTag; + return $open . $this->content . $close; } public function auth() { - $openingTag = ''; - - return $openingTag . $this->content . $closingTag; + return ""; } public function guest() { - $openingTag = ''; - - return $openingTag . $this->content . $closingTag; + return ""; } public function wildcard($tag) { - return ''; + return ""; } }