Page MenuHomePhorge

No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/src/app/Console/Commands/User/AliasesCommand.php b/src/app/Console/Commands/User/AliasesCommand.php
new file mode 100644
index 00000000..aa240f98
--- /dev/null
+++ b/src/app/Console/Commands/User/AliasesCommand.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\Command;
+
+class AliasesCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:aliases {user}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "List a user's aliases";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = $this->getUser($this->argument('user'));
+
+ if (!$user) {
+ $this->error("User not found.");
+ return 1;
+ }
+
+ foreach ($user->aliases as $alias) {
+ $this->info("{$alias->alias}");
+ }
+ }
+}
diff --git a/src/app/Console/Commands/UserAliasesCommand.php b/src/app/Console/Commands/UserAliasesCommand.php
new file mode 100644
index 00000000..a19f5cde
--- /dev/null
+++ b/src/app/Console/Commands/UserAliasesCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class UserAliasesCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\UserAlias::class;
+ protected $objectName = 'user-alias';
+ protected $objectNamePlural = 'user-aliases';
+ protected $objectTitle = 'alias';
+}
diff --git a/src/app/Console/ObjectCommand.php b/src/app/Console/ObjectCommand.php
index a2ae4414..52750b96 100644
--- a/src/app/Console/ObjectCommand.php
+++ b/src/app/Console/ObjectCommand.php
@@ -1,74 +1,80 @@
<?php
namespace App\Console;
use Illuminate\Support\Facades\Cache;
abstract class ObjectCommand extends Command
{
/**
* Specify a command prefix, if any.
*
* For example, \App\Console\Commands\Scalpel\User\CreateCommand uses prefix 'scalpel'.
*
* @var string
*/
protected $commandPrefix = null;
/**
* The object class that we are operating on, for example \App\User::class
*
* @var string
*/
protected $objectClass;
/**
* The (simple) object name, such as 'domain' or 'user'. Corresponds with the mandatory command-line option
* to identify the object from its corresponding model.
*
* @var string
*/
protected $objectName;
+ /**
+ * The plural of the object name, if something specific (goose -> geese).
+ *
+ * @var string
+ */
+ protected $objectNamePlural;
+
/**
* A column name other than the primary key can be used to identify an object, such as 'email' for users,
* 'namespace' for domains, and 'title' for SKUs.
*
* @var string
*/
protected $objectTitle;
/**
* Placeholder for column name attributes for objects, from which command-line switches and attribute names can be
* generated.
*
* @var array
*/
protected $properties;
-
/**
* List of cache keys to refresh after updating/creating an object
*
* @var array
*/
protected $cacheKeys = [];
/**
* Reset the cache for specified object using defined cacheKeys.
*
* @param object $object The object that was updated/created
*/
protected function cacheRefresh($object): void
{
foreach ($this->cacheKeys as $cacheKey) {
foreach ($object->toArray() as $propKey => $propValue) {
if (!is_object($propValue)) {
$cacheKey = str_replace('%' . $propKey . '%', $propValue, $cacheKey);
}
}
Cache::forget($cacheKey);
}
}
}
diff --git a/src/app/Console/ObjectListCommand.php b/src/app/Console/ObjectListCommand.php
index 21d13d8a..8b02a86e 100644
--- a/src/app/Console/ObjectListCommand.php
+++ b/src/app/Console/ObjectListCommand.php
@@ -1,56 +1,61 @@
<?php
namespace App\Console;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* This abstract class provides a means to treat objects in our model using CRUD, with the exception that
* this particular abstract class lists objects.
*/
abstract class ObjectListCommand extends ObjectCommand
{
public function __construct()
{
- $this->description = "List {$this->objectName}s";
+ $this->description = "List all {$this->objectName} objects";
$this->signature = $this->commandPrefix ? $this->commandPrefix . ":" : "";
- $this->signature .= "{$this->objectName}s";
+
+ if (!empty($this->objectNamePlural)) {
+ $this->signature .= "{$this->objectNamePlural}";
+ } else {
+ $this->signature .= "{$this->objectName}s";
+ }
$classes = class_uses_recursive($this->objectClass);
if (in_array(SoftDeletes::class, $classes)) {
$this->signature .= " {--with-deleted : Include deleted {$this->objectName}s}";
}
$this->signature .= " {--attr=* : Attributes other than the primary unique key to include}";
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$classes = class_uses_recursive($this->objectClass);
if (in_array(SoftDeletes::class, $classes) && $this->option('with-deleted')) {
$objects = $this->objectClass::withTrashed();
} else {
$objects = new $this->objectClass();
}
$objects->each(
function ($object) {
if ($object->deleted_at) {
$this->info("{$this->toString($object)} (deleted at {$object->deleted_at}");
} else {
$this->info("{$this->toString($object)}");
}
}
);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Jan 31, 7:21 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
426447
Default Alt Text
(5 KB)

Event Timeline