Page MenuHomePhorge

D1996.1775158360.diff
No OneTemporary

Authored By
Unknown
Size
29 KB
Referenced Files
None
Subscribers
None

D1996.1775158360.diff

diff --git a/bin/doctum b/bin/doctum
--- a/bin/doctum
+++ b/bin/doctum
@@ -4,7 +4,7 @@
pushd ${cwd}/../src/
-rm -rf cache/store/
+rm -rf ../docs/build/main/ cache/store/
php -dmemory_limit=-1 \
vendor/bin/doctum.php \
diff --git a/src/app/Console/Command.php b/src/app/Console/Command.php
--- a/src/app/Console/Command.php
+++ b/src/app/Console/Command.php
@@ -27,10 +27,18 @@
*/
public function getObject($objectClass, $objectIdOrTitle, $objectTitle)
{
- $object = $objectClass::find($objectIdOrTitle);
+ if ($this->hasOption('with-deleted') && $this->option('with-deleted')) {
+ $object = $objectClass::withTrashed()->find($objectIdOrTitle);
+ } else {
+ $object = $objectClass::find($objectIdOrTitle);
+ }
if (!$object && !empty($objectTitle)) {
- $object = $objectClass::where($objectTitle, $objectIdOrTitle)->first();
+ if ($this->hasOption('with-deleted') && $this->option('with-deleted')) {
+ $object = $objectClass::withTrashed()->where($objectTitle, $objectIdOrTitle)->first();
+ } else {
+ $object = $objectClass::where($objectTitle, $objectIdOrTitle)->first();
+ }
}
return $object;
diff --git a/src/app/Console/Commands/DiscountsCommand.php b/src/app/Console/Commands/DiscountsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/DiscountsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class DiscountsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Discount::class;
+ protected $objectName = 'discount';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/DomainsCommand.php b/src/app/Console/Commands/DomainsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/DomainsCommand.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+/**
+ * List domains.
+ *
+ * Example usage:
+ *
+ * ```
+ * $ ./artisan domains
+ * 96217419
+ * 502526624
+ * 539082236
+ * (...)
+ * ```
+ *
+ * To include specific attributes, use `--attr` (allowed multiple times):
+ *
+ * ```
+ * $ ./artisan domains --attr=namespace --attr=status
+ * 96217419 attorneymail.ch 51
+ * 502526624 example.net 51
+ * 539082236 collaborative.li 51
+ * (...)
+ * ```
+ */
+class DomainsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = 'namespace';
+}
diff --git a/src/app/Console/Commands/EntitlementsCommand.php b/src/app/Console/Commands/EntitlementsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/EntitlementsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class EntitlementsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/PackagesCommand.php b/src/app/Console/Commands/PackagesCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/PackagesCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class PackagesCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Package::class;
+ protected $objectName = 'package';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/PlansCommand.php b/src/app/Console/Commands/PlansCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/PlansCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class PlansCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Plan::class;
+ protected $objectName = 'plan';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Discount/CreateCommand.php b/src/app/Console/Commands/Scalpel/Discount/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Discount/CreateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Discount;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Discount::class;
+ protected $objectName = 'discount';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Discount/ReadCommand.php b/src/app/Console/Commands/Scalpel/Discount/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Discount/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Discount;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Discount::class;
+ protected $objectName = 'discount';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Domain/CreateCommand.php b/src/app/Console/Commands/Scalpel/Domain/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Domain/CreateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Domain;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Domain/ReadCommand.php b/src/app/Console/Commands/Scalpel/Domain/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Domain/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Domain;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = 'namespace';
+}
diff --git a/src/app/Console/Commands/Scalpel/Domain/UpdateCommand.php b/src/app/Console/Commands/Scalpel/Domain/UpdateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Domain/UpdateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Domain;
+
+use App\Console\ObjectUpdateCommand;
+
+class UpdateCommand extends ObjectUpdateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = 'namespace';
+}
diff --git a/src/app/Console/Commands/Scalpel/Entitlement/CreateCommand.php b/src/app/Console/Commands/Scalpel/Entitlement/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Entitlement/CreateCommand.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Entitlement;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+
+ public function handle()
+ {
+ $this->properties = $this->getProperties();
+
+ $entitleable = call_user_func_array(
+ [$this->properties['entitleable_type'], 'find'],
+ [$this->properties['entitleable_id']]
+ );
+
+ if (!$entitleable) {
+ $this->error("No such {$this->properties['entitleable_type']}");
+ return 1;
+ }
+
+ if (!array_key_exists('entitleable_id', $this->properties)) {
+ $this->error("Specify --entitleable_id");
+ }
+
+ if (array_key_exists('sku_id', $this->properties)) {
+ $sku = \App\Sku::find($this->properties['sku_id']);
+
+ if (!$sku) {
+ $this->error("No such SKU {$this->properties['sku_id']}");
+ return 1;
+ }
+
+ if ($this->properties['cost'] == null) {
+ $this->properties['cost'] = $sku->cost;
+ }
+ }
+
+ if (array_key_exists('wallet_id', $this->properties)) {
+ $wallet = \App\Wallet::find($this->properties['wallet_id']);
+
+ if (!$wallet) {
+ $this->error("No such wallet {$this->properties['wallet_id']}");
+ return 1;
+ }
+ }
+
+ parent::handle();
+ }
+}
diff --git a/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php b/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Entitlement;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Entitlement/UpdateCommand.php b/src/app/Console/Commands/Scalpel/Entitlement/UpdateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Entitlement/UpdateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Entitlement;
+
+use App\Console\ObjectUpdateCommand;
+
+class UpdateCommand extends ObjectUpdateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Package/ReadCommand.php b/src/app/Console/Commands/Scalpel/Package/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Package/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Package;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Package::class;
+ protected $objectName = 'package';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Plan/ReadCommand.php b/src/app/Console/Commands/Scalpel/Plan/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Plan/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Plan;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Plan::class;
+ protected $objectName = 'plan';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Sku/ReadCommand.php b/src/app/Console/Commands/Scalpel/Sku/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Sku/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Sku;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Sku::class;
+ protected $objectName = 'sku';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Transaction/ReadCommand.php b/src/app/Console/Commands/Scalpel/Transaction/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Transaction/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Transaction;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Transaction::class;
+ protected $objectName = 'transaction';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/User/CreateCommand.php b/src/app/Console/Commands/Scalpel/User/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/User/CreateCommand.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\User;
+
+use App\Console\ObjectCreateCommand;
+
+/**
+ * Create a user at the lowest level of control over the exact database entry.
+ *
+ * For example:
+ *
+ * ```
+ * $ ./artisan scalpel:user:create --id=3 --email=john.doe@kolab.local --password=somehash --status=3
+ * ```
+ *
+ * **NOTE**: Executes the model's create() function, and therefore the necessary observer routines (meaning, basically,
+ * actions such as the creation of wallet will be executed), **HOWEVER** no entitlements will be associated with the
+ * user.
+ */
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/User/ReadCommand.php b/src/app/Console/Commands/Scalpel/User/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/User/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\User;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/Scalpel/UserSetting/ReadCommand.php b/src/app/Console/Commands/Scalpel/UserSetting/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/UserSetting/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\UserSetting;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\UserSetting::class;
+ protected $objectName = 'user-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Wallet/ReadCommand.php b/src/app/Console/Commands/Scalpel/Wallet/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Wallet/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Wallet;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/WalletSetting/ReadCommand.php b/src/app/Console/Commands/Scalpel/WalletSetting/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/WalletSetting/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\WalletSetting;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\WalletSetting::class;
+ protected $objectName = 'wallet-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/TransactionsCommand.php b/src/app/Console/Commands/TransactionsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/TransactionsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class TransactionsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Transaction::class;
+ protected $objectName = 'transaction';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/UserSettingsCommand.php b/src/app/Console/Commands/UserSettingsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/UserSettingsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class UserSettingsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\UserSetting::class;
+ protected $objectName = 'user-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/UsersCommand.php b/src/app/Console/Commands/UsersCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/UsersCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class UsersCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/WalletSettingsCommand.php b/src/app/Console/Commands/WalletSettingsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/WalletSettingsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class WalletSettingsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\WalletSetting::class;
+ protected $objectName = 'wallet-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/WalletsCommand.php b/src/app/Console/Commands/WalletsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/WalletsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class WalletsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/ObjectCommand.php b/src/app/Console/ObjectCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectCommand.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Console;
+
+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;
+
+ /**
+ * 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;
+}
diff --git a/src/app/Console/ObjectCreateCommand.php b/src/app/Console/ObjectCreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectCreateCommand.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace App\Console;
+
+/**
+ * This abstract class provides a means to treat objects in our model using CRUD.
+ */
+abstract class ObjectCreateCommand extends ObjectCommand
+{
+ public function __construct()
+ {
+ $this->description = "Create a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:create",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName
+ );
+
+ $class = new $this->objectClass();
+
+ foreach ($class->getFillable() as $fillable) {
+ $this->signature .= " {--{$fillable}=}";
+ }
+
+ parent::__construct();
+ }
+
+ public function getProperties()
+ {
+ if (!empty($this->properties)) {
+ return $this->properties;
+ }
+
+ $class = new $this->objectClass();
+
+ $this->properties = [];
+
+ foreach ($class->getFillable() as $fillable) {
+ $this->properties[$fillable] = $this->option($fillable);
+ }
+
+ return $this->properties;
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $this->getProperties();
+
+ $class = new $this->objectClass();
+
+ $object = $this->objectClass::create($this->properties);
+
+ if ($object) {
+ $this->info($object->{$class->getKeyName()});
+ } else {
+ $this->error("Object could not be created.");
+ }
+
+ return $object;
+ }
+}
diff --git a/src/app/Console/ObjectListCommand.php b/src/app/Console/ObjectListCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectListCommand.php
@@ -0,0 +1,56 @@
+<?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";
+
+ $classes = class_uses_recursive($this->objectClass);
+
+ $this->signature = $this->commandPrefix ? $this->commandPrefix . ":" : "";
+ $this->signature .= "{$this->objectName}s";
+
+ 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)}");
+ }
+ }
+ );
+ }
+}
diff --git a/src/app/Console/ObjectReadCommand.php b/src/app/Console/ObjectReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectReadCommand.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Console;
+
+/**
+ * This abstract class provides a means to treat objects in our model using CRUD.
+ */
+abstract class ObjectReadCommand extends ObjectCommand
+{
+ public function __construct()
+ {
+ $this->description = "Read a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:read {%s}",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName,
+ $this->objectName
+ );
+
+ $this->signature .= " {--attr=* : Attributes other than the primary unique key to include}";
+
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $argument = $this->argument($this->objectName);
+
+ $object = $this->getObject($this->objectClass, $argument, $this->objectTitle);
+
+ if (!$object) {
+ $this->error("No such {$this->objectName} {$argument}");
+ return 1;
+ }
+
+ $this->info($this->toString($object));
+ }
+}
diff --git a/src/app/Console/ObjectRelationListCommand.php b/src/app/Console/ObjectRelationListCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectRelationListCommand.php
@@ -0,0 +1,91 @@
+<?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' relations.
+ */
+abstract class ObjectRelationListCommand extends ObjectCommand
+{
+ /**
+ * The "relation" -- a method or property.
+ *
+ * @var string
+ */
+ protected $objectRelation;
+
+ /**
+ * Supplement the base command constructor with a derived or generated signature and
+ * description.
+ *
+ * @return mixed
+ */
+ public function __construct()
+ {
+ $this->description = "List {$this->objectRelation} for a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:%s {%s}",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName,
+ $this->objectRelation,
+ $this->objectName
+ );
+
+ $this->signature .= " {--attr=* : Attributes other than the primary unique key to include}";
+
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $argument = $this->argument($this->objectName);
+
+ $object = $this->getObject(
+ $this->objectClass,
+ $argument,
+ $this->objectTitle
+ );
+
+ if (!$object) {
+ $this->error("No such {$this->objectName} {$argument}");
+ return 1;
+ }
+
+ if (method_exists($object, $this->objectRelation)) {
+ $result = call_user_func([$object, $this->objectRelation]);
+ } elseif (property_exists($object, $this->objectRelation)) {
+ $result = $object->{"{$this->objectRelation}"};
+ } else {
+ $this->error("No such relation {$this->objectRelation}");
+ return 1;
+ }
+
+ if ($result instanceof \Illuminate\Database\Eloquent\Collection) {
+ $result->each(
+ function ($entry) {
+ $this->info($this->toString($entry));
+ }
+ );
+ } elseif ($result instanceof \Illuminate\Database\Eloquent\Relations\Relation) {
+ $result->each(
+ function ($entry) {
+ $this->info($this->toString($entry));
+ }
+ );
+ } elseif (is_array($result)) {
+ foreach ($result as $entry) {
+ $this->info($this->toString($entry));
+ }
+ } else {
+ $this->info($this->toString($result));
+ }
+ }
+}
diff --git a/src/app/Console/ObjectUpdateCommand.php b/src/app/Console/ObjectUpdateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectUpdateCommand.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace App\Console;
+
+use Illuminate\Support\Facades\Schema;
+
+/**
+ * This abstract class provides a means to treat objects in our model using CRUD.
+ */
+abstract class ObjectUpdateCommand extends ObjectCommand
+{
+ public function __construct()
+ {
+ $this->description = "Update a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:update {%s}",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName,
+ $this->objectName
+ );
+
+ $class = new $this->objectClass();
+
+ foreach (Schema::getColumnListing($class->getTable()) as $column) {
+ if ($column == "id") {
+ continue;
+ }
+
+ $this->signature .= " {--{$column}=}";
+ }
+
+ $this->signature .= sprintf(
+ " {--with-deleted : Include deleted %ss}",
+ $this->objectName
+ );
+
+ parent::__construct();
+ }
+
+ public function getProperties()
+ {
+ if (!empty($this->properties)) {
+ return $this->properties;
+ }
+
+ $class = new $this->objectClass();
+
+ $this->properties = [];
+
+ foreach (Schema::getColumnListing($class->getTable()) as $column) {
+ if ($column == "id") {
+ continue;
+ }
+
+ if (($value = $this->option($column)) !== null) {
+ $this->properties[$column] = $value;
+ }
+ }
+
+ return $this->properties;
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $argument = $this->argument($this->objectName);
+
+ $object = $this->getObject($this->objectClass, $argument, $this->objectTitle);
+
+ if (!$object) {
+ $this->error("No such {$this->objectName} {$argument}");
+ return 1;
+ }
+
+ foreach ($this->getProperties() as $property => $value) {
+ if ($property == "deleted_at" && $value == "null") {
+ $value = null;
+ }
+
+ $object->{$property} = $value;
+ }
+
+ $object->timestamps = false;
+
+ $object->save(['timestamps' => false]);
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 2, 7:32 PM (1 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18820509
Default Alt Text
D1996.1775158360.diff (29 KB)

Event Timeline