Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117754883
ObjectRelationListCommand.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
ObjectRelationListCommand.php
View Options
<?php
namespace
App\Console
;
/**
* 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
));
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 7:26 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18763455
Default Alt Text
ObjectRelationListCommand.php (2 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline