Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F221574
Rbit.php
Firehed (Eric Stern)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
Firehed
Oct 20 2014, 8:02 PM
2014-10-20 20:02:03 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
Rbit.php
View Options
<?php
namespace
Firehed\Input\Objects
;
use
Firehed\Input\ValidationInterface
;
use
Firehed\Input\Objects
as
IO
;
use
Boo\Baz
;
function
foobar
(
Baz
$zz
)
{
foothebar
();
foobar
();
}
//use const Z\Y as X;
//use function func1;
//use function func2 as f2;
trait
TRAITNAME
{
use
TRAIT1
;
use
T\TRAIT2
;
use
\TRAIT3
;
}
abstract
class
A
{}
final
class
B
{}
new
A\B
;
//new namespace\A\B;
/**
* THIS IS NOT READY FOR USE YET!
*
* At present, there are some incomplete inputs, but a skeleton was necessary
* as part of a proof-of-concept for recursively handling nested objects as
* defined by the `related_rbits` field, and to serve as a general example of
* how to define a data structure as an input type.
*/
class
Rbit
extends
InputObject
implements
ValidationInterface
{
use
TRAITNAME
;
use
T4
,
T5
;
use
T6
,
T7
{
T7
::
x
insteadof
T6
;
T6
::
y
insteadof
T7
;
T7
::
y
as
z
;
}
use
\Wierd\TraitName
;
private
$validated
;
// Needs:
// receive_time: time
// properties: dictionary with type dependency
protected
function
validate
(
$value
)
{
new
Foo\Bar
;
if
(!
is_array
(
$value
))
{
return
false
;
}
$parsed
=
new
\Firehed\Input\ParsedInput
(
$value
);
try
{
$this
->
validated
=
$parsed
->
sanitize
([])
// Sanitized already, tis is safe
->
validate
(
$this
);
return
true
;
}
catch
(
\Firehed\Input\InputException
$e
)
{
return
false
;
}
}
// validate
public
function
evaluate
()
{
// Performs validation
parent
::
evaluate
();
// Provide closure back into itself to allow recursion
$parse_rbit
=
function
(
$rbit
)
use
(&
$parse_rbit
)
{
$out
=
[
// 'receive_time' => $rbit['receive_time'],
// 'properties' => $rbit['properties'], <== decode?
'source'
=>
$rbit
[
'source'
],
'type'
=>
$rbit
[
'type'
],
'note'
=>
$rbit
[
'note'
],
'related_rbits'
=>
[],
];
// Recursively parse any related rbits
if
(
$rbit
[
'related_rbits'
])
{
foreach
(
$rbit
[
'related_rbits'
]
as
$related
)
{
$out
[
'related_rbits'
][]
=
$parse_rbit
(
$related
);
}
}
return
$out
;
};
// At some point, we should create an actual Rbit object/structure in
// the system, and this should be updated to return it
return
$parse_rbit
(
$this
->
validated
);
}
// evaluate
public
function
getRequiredInputs
()
{
$type
=
(
new
IO\String
())->
setMax
(
255
);
return
[
// 'receive_time' => IO\Timestamp,
'source'
=>
(
new
IO\String
())->
setMax
(
255
),
'type'
=>
$type
,
// Add an RbitProperty type extending Dictionary so it can do
// conditional validation based on the 'type' value. Its
// constructor should require (and configure) the dependency
// 'properties' => IO\RbitProperties($type),
];
}
// getRequiredInputs
public
function
getOptionalInputs
()
{
return
[
'note'
=>
(
new
IO\String
())->
setMax
(
65535
),
'related_rbits'
=>
new
IO\ListOf
(
new
self
()),
];
}
// getOptionalInputs
}
File Metadata
Details
Attached
Mime Type
text/x-php
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/wz/c6/iwhfnrgu677eji44
Default Alt Text
Rbit.php (3 KB)
Attached To
Mode
D10728: Allow `arc liberate` to handle traits and namespaces
Attached
Detach File
Event Timeline
Log In to Comment