Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2680392
PhutilConsoleView.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
2 KB
Referenced Files
None
Subscribers
None
PhutilConsoleView.php
View Options
<?php
abstract
class
PhutilConsoleView
extends
Phobject
{
private
$console
;
abstract
protected
function
drawView
(
)
;
final
public
function
setConsole
(
PhutilConsole
$console
)
{
$this
->
console
=
$console
;
return
$this
;
}
final
public
function
getConsole
(
)
{
if
(
$this
->
console
)
{
return
$this
->
console
;
}
return
PhutilConsole
::
getConsole
(
)
;
}
/**
* Draw a view to the console.
*
* @return $this
* @task draw
*/
final
public
function
draw
(
)
{
$string
=
$this
->
drawConsoleString
(
)
;
$console
=
$this
->
getConsole
(
)
;
$console
->
writeOut
(
'%s'
,
$string
)
;
return
$this
;
}
/**
* Draw a view to a string and return it.
*
* @return string Console-printable string.
* @task draw
*/
final
public
function
drawConsoleString
(
)
{
$view
=
$this
->
drawView
(
)
;
$parts
=
$this
->
reduceView
(
$view
)
;
$out
=
array
(
)
;
foreach
(
$parts
as
$part
)
{
$out
[
]
=
PhutilTerminalString
::
escapeStringValue
(
$part
,
true
)
;
}
return
implode
(
''
,
$out
)
;
}
/**
* Reduce a view to a list of simple, unnested parts.
*
* @param wild $view Any drawable view.
* @return list<wild> List of unnested drawables.
* @task draw
*/
private
function
reduceView
(
$view
)
{
if
(
$view
instanceof
PhutilConsoleView
)
{
$view
=
$view
->
drawView
(
)
;
return
$this
->
reduceView
(
$view
)
;
}
if
(
is_array
(
$view
)
)
{
$parts
=
array
(
)
;
foreach
(
$view
as
$item
)
{
foreach
(
$this
->
reduceView
(
$item
)
as
$part
)
{
$parts
[
]
=
$part
;
}
}
return
$parts
;
}
return
array
(
$view
)
;
}
/* -( Drawing Utilities )-------------------------------------------------- */
/**
* @param list<wild> $parts List of views, one per line.
* @return wild Each view rendered on a separate line.
*/
final
protected
function
drawLines
(
array
$parts
)
{
$result
=
array
(
)
;
foreach
(
$parts
as
$part
)
{
if
(
$part
!==
null
)
{
$result
[
]
=
$part
;
$result
[
]
=
"\n"
;
}
}
return
$result
;
}
final
protected
function
implode
(
$separator
,
array
$items
)
{
$result
=
array
(
)
;
foreach
(
$items
as
$item
)
{
$result
[
]
=
$item
;
$result
[
]
=
$separator
;
}
array_pop
(
$result
)
;
return
$result
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Dec 19, 17:00 (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1014853
Default Alt Text
PhutilConsoleView.php (2 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment