Files
laravel-manager-packagist/src/Support/Sharing/Sharers.php
T
2026-12-05 17:00:22 +00:00

36 lines
1.1 KiB
PHP

<?php
namespace IriksIT\Manager\Support\Sharing;
use IriksIT\Manager\Contracts\Sharer;
/** Which code posts on which platform: `manager.sharing.platforms` (name => class of a `Sharer`). */
final class Sharers
{
/** @return list<string> the names of the platforms, as the routes and the database know them */
public function names(): array
{
return array_values(array_filter(array_keys((array) config('manager.sharing.platforms', [])), fn ($name) => is_string($name) && preg_match('/^[a-z][a-z0-9_]{0,19}$/', $name) === 1));
}
public function has(string $name): bool
{
return in_array($name, $this->names(), true);
}
public function for(string $name): Sharer
{
$class = config("manager.sharing.platforms.{$name}");
abort_unless($this->has($name) && is_string($class) && is_subclass_of($class, Sharer::class), 404);
return app($class);
}
/** The owner has connected this platform. */
public function isConnected(string $name): bool
{
return $this->has($name) && $this->for($name)->connection() !== null;
}
}