Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F118215709
DarkConsoleCore.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jun 18, 12:28
Size
4 KB
Mime Type
text/x-php
Expires
Fri, Jun 20, 12:28 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
26837700
Attached To
rPH Phabricator
DarkConsoleCore.php
View Options
<?php
/**
* @group console
*/
final
class
DarkConsoleCore
{
const
PLUGIN_ERRORLOG
=
'ErrorLog'
;
const
PLUGIN_SERVICES
=
'Services'
;
const
PLUGIN_EVENT
=
'Event'
;
const
PLUGIN_XHPROF
=
'XHProf'
;
const
PLUGIN_REQUEST
=
'Request'
;
public
static
function
getPlugins
()
{
return
array
(
self
::
PLUGIN_ERRORLOG
,
self
::
PLUGIN_REQUEST
,
self
::
PLUGIN_SERVICES
,
self
::
PLUGIN_EVENT
,
self
::
PLUGIN_XHPROF
,
);
}
private
$plugins
=
array
();
private
$settings
;
private
$coredata
;
public
function
getPlugin
(
$plugin_name
)
{
return
idx
(
$this
->
plugins
,
$plugin_name
);
}
public
function
__construct
()
{
foreach
(
self
::
getPlugins
()
as
$plugin_name
)
{
$plugin
=
self
::
newPlugin
(
$plugin_name
);
if
(
$plugin
->
isPermanent
()
||
!
isset
(
$disabled
[
$plugin_name
]))
{
if
(
$plugin
->
shouldStartup
())
{
$plugin
->
didStartup
();
$plugin
->
setConsoleCore
(
$this
);
$this
->
plugins
[
$plugin_name
]
=
$plugin
;
}
}
}
}
public
static
function
newPlugin
(
$plugin
)
{
$class
=
'DarkConsole'
.
$plugin
.
'Plugin'
;
return
newv
(
$class
,
array
());
}
public
function
getEnabledPlugins
()
{
return
$this
->
plugins
;
}
public
function
render
(
AphrontRequest
$request
)
{
$user
=
$request
->
getUser
();
$plugins
=
$this
->
getEnabledPlugins
();
foreach
(
$plugins
as
$plugin
)
{
$plugin
->
setRequest
(
$request
);
$plugin
->
willShutdown
();
}
foreach
(
$plugins
as
$plugin
)
{
$plugin
->
didShutdown
();
}
foreach
(
$plugins
as
$plugin
)
{
$plugin
->
setData
(
$plugin
->
generateData
());
}
$selected
=
$user
->
getConsoleTab
();
$visible
=
$user
->
getConsoleVisible
();
if
(!
isset
(
$plugins
[
$selected
]))
{
$selected
=
head_key
(
$plugins
);
}
$tabs
=
array
();
foreach
(
$plugins
as
$key
=>
$plugin
)
{
$tabs
[
$key
]
=
array
(
'name'
=>
$plugin
->
getName
(),
'panel'
=>
$plugin
->
render
(),
);
}
$tabs_markup
=
array
();
$panel_markup
=
array
();
foreach
(
$tabs
as
$key
=>
$data
)
{
$is_selected
=
(
$key
==
$selected
);
if
(
$is_selected
)
{
$style
=
null
;
$tabclass
=
'dark-console-tab-selected'
;
}
else
{
$style
=
'display: none;'
;
$tabclass
=
null
;
}
$tabs_markup
[]
=
javelin_tag
(
'a'
,
array
(
'class'
=>
"dark-console-tab {$tabclass}"
,
'sigil'
=>
'dark-console-tab'
,
'id'
=>
'dark-console-tab-'
.
$key
,
),
(
string
)
$data
[
'name'
]);
$panel_markup
[]
=
javelin_render_tag
(
'div'
,
array
(
'class'
=>
'dark-console-panel dark-console-panel-'
.
$key
,
'style'
=>
$style
,
'sigil'
=>
'dark-console-panel'
,
),
(
string
)
$data
[
'panel'
]);
}
$console
=
javelin_render_tag
(
'table'
,
array
(
'class'
=>
'dark-console'
,
'sigil'
=>
'dark-console'
,
'style'
=>
$visible
?
''
:
'display: none;'
,
),
'<tr>'
.
'<th class="dark-console-tabs">'
.
implode
(
"
\n
"
,
$tabs_markup
).
'</th>'
.
'<td>'
.
implode
(
"
\n
"
,
$panel_markup
).
'</td>'
.
'</tr>'
);
if
(!
empty
(
$_COOKIE
[
'phsid'
]))
{
$console
=
str_replace
(
$_COOKIE
[
'phsid'
],
phutil_escape_html
(
'<session-key>'
),
$console
);
}
if
(
$request
->
isAjax
())
{
// for ajax this HTML gets updated on the client
$request_history
=
null
;
}
else
{
$request_table_header
=
'<div class="dark-console-panel-request-log-separator"></div>'
;
$rows
=
array
();
$table
=
new
AphrontTableView
(
$rows
);
$table
->
setHeaders
(
array
(
'Sequence'
,
'Type'
,
'URI'
,
));
$table
->
setColumnClasses
(
array
(
''
,
''
,
'wide'
,
));
$request_table
=
$request_table_header
.
$table
->
render
();
$request_history
=
javelin_render_tag
(
'table'
,
array
(
'class'
=>
'dark-console dark-console-request-log'
,
'sigil'
=>
'dark-console-request-log'
,
'style'
=>
$visible
?
''
:
'display: none;'
,
),
'<tr>'
.
'<th class="dark-console-tabs">'
.
phutil_tag
(
'a'
,
array
(
'class'
=>
'dark-console-tab dark-console-tab-selected'
,
),
'Request Log'
).
'</th>'
.
'<td>'
.
javelin_render_tag
(
'div'
,
array
(
'class'
=>
'dark-console-panel dark-console-panel-RequestLog'
,
),
$request_table
).
'</td>'
.
'</tr>'
);
}
return
"
\n\n\n\n
"
.
$console
.
$request_history
.
"
\n\n\n\n
"
;
}
}
Event Timeline
Log In to Comment