v0.9.10
This commit is contained in:
commit
d59ee3834d
297 files changed
+20527
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user