Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1168348
RunEventCommand.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Sep 24, 10:24 AM
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Sep 26, 10:24 AM (18 h, 52 m)
Engine
blob
Format
Raw Data
Handle
756874
Attached To
rINP In-Portal
RunEventCommand.php
View Options
<?php
/**
* @version $Id: RunEventCommand.php 16283 2015-09-27 11:22:39Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2015 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
namespace
InPortal\Core\kernel\Console\Command
;
use
Stecman\Component\Symfony\Console\BashCompletion\CompletionContext
;
use
Symfony\Component\Console\Input\InputArgument
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Output\OutputInterface
;
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
RunEventCommand
extends
AbstractCommand
{
/**
* Configures the current command.
*
* @return void
*/
protected
function
configure
()
{
$this
->
setName
(
'event:run'
)
->
setDescription
(
'Executes an event'
)
->
addArgument
(
'event_name'
,
InputArgument
::
REQUIRED
,
'Event name (e.g. "<info>adm:OnDoSomething</info>")'
);
}
/**
* Executes the current command.
*
* @param InputInterface $input An InputInterface instance.
* @param OutputInterface $output An OutputInterface instance.
*
* @return null|integer
*/
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
)
{
$event_name
=
$this
->
io
->
getArgument
(
'event_name'
);
$run_event
=
new
\kEvent
(
$event_name
);
$this
->
Application
->
HandleEvent
(
$run_event
);
return
$run_event
->
status
==
\kEvent
::
erSUCCESS
?
0
:
64
;
}
/**
* Return possible values for the named argument.
*
* @param string $argumentName Argument name.
* @param CompletionContext $context Completion context.
*
* @return array
*/
public
function
completeArgumentValues
(
$argumentName
,
CompletionContext
$context
)
{
$suggestions
=
parent
::
completeArgumentValues
(
$argumentName
,
$context
);
if
(
$argumentName
===
'event_name'
)
{
$event_name
=
$context
->
getCurrentWord
();
// Suggest unit config prefixes.
if
(
strpos
(
$event_name
,
':'
)
===
false
)
{
return
$this
->
Application
->
UnitConfigReader
->
getPrefixes
(
false
);
}
try
{
$event
=
new
\kEvent
(
$event_name
);
}
catch
(
\InvalidArgumentException
$e
)
{
// Invalid event name.
return
array
();
}
// Unknown unit.
if
(
!
$this
->
Application
->
prefixRegistred
(
$event
->
Prefix
)
)
{
return
array
();
}
// Suggest event names.
$suggestions
=
array
();
$reflection
=
new
\ReflectionClass
(
$this
->
Application
->
makeClass
(
$event
->
Prefix
.
'_EventHandler'
)
);
foreach
(
$reflection
->
getMethods
()
as
$method
)
{
if
(
substr
(
$method
->
getName
(),
0
,
2
)
===
'On'
)
{
$suggestions
[]
=
$event
->
Prefix
.
':'
.
$method
->
getName
();
}
}
return
$suggestions
;
}
return
$suggestions
;
}
}
Event Timeline
Log In to Comment