本文整理汇总了PHP中Bitrix\Main\Event类的典型用法代码示例。如果您正苦于以下问题:PHP Event类的具体用法?PHP Event怎么用?PHP Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInstance
private static function getInstance()
{
if (self::$instance) {
return self::$instance;
}
$loader = new BitrixLoader($_SERVER['DOCUMENT_ROOT']);
$c = Configuration::getInstance();
$config = $c->get('maximaster');
$twigConfig = (array) $config['tools']['twig'];
$defaultConfig = array('debug' => false, 'charset' => SITE_CHARSET, 'cache' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/maximaster/tools.twig', 'auto_reload' => isset($_GET['clear_cache']) && strtoupper($_GET['clear_cache']) == 'Y', 'autoescape' => false);
$twigOptions = array_merge($defaultConfig, $twigConfig);
$twig = new \Twig_Environment($loader, $twigOptions);
if ($twig->isDebug()) {
$twig->addExtension(new \Twig_Extension_Debug());
}
$twig->addExtension(new BitrixExtension());
$twig->addExtension(new CustomFunctionsExtension());
$event = new Event('', 'onAfterTwigTemplateEngineInited', array($twig));
$event->send();
if ($event->getResults()) {
foreach ($event->getResults() as $evenResult) {
if ($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS) {
$twig = current($evenResult->getParameters());
}
}
}
return self::$instance = $twig;
}
示例2: onExecuteStartWriting
function onExecuteStartWriting(\Bitrix\Main\Event $event)
{
$parameters = $event->getParameters();
$userId = $parameters[0];
$dialogId = $parameters[1] . $parameters[2];
if ($userId > 0) {
if (!\Bitrix\Main\Loader::includeModule('pull')) {
return;
}
\CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS');
if (intval($dialogId) > 0) {
\CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
} elseif (substr($dialogId, 0, 4) == 'chat') {
$chatId = substr($dialogId, 4);
$arRelation = \CIMChat::GetRelationById($chatId);
unset($arRelation[$userId]);
$pullMessage = array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId));
\CPullStack::AddByUsers(array_keys($arRelation), $pullMessage);
$orm = \Bitrix\Im\ChatTable::getById($chatId);
$chat = $orm->fetch();
if ($chat['TYPE'] == IM_MESSAGE_OPEN) {
\CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $pullMessage);
}
}
}
}
示例3: initClassesList
public static function initClassesList()
{
if (static::$classes !== null) {
return true;
}
$classes = array('\\Bitrix\\Sale\\Delivery\\ExtraServices\\Enum' => 'lib/delivery/extra_services/enum.php', '\\Bitrix\\Sale\\Delivery\\ExtraServices\\Store' => 'lib/delivery/extra_services/store.php', '\\Bitrix\\Sale\\Delivery\\ExtraServices\\String' => 'lib/delivery/extra_services/string.php', '\\Bitrix\\Sale\\Delivery\\ExtraServices\\Checkbox' => 'lib/delivery/extra_services/checkbox.php');
\Bitrix\Main\Loader::registerAutoLoadClasses('sale', $classes);
unset($classes['\\Bitrix\\Sale\\Delivery\\ExtraServices\\Store']);
static::$classes = array_keys($classes);
$event = new Event('sale', 'onSaleDeliveryExtraServicesClassNamesBuildList');
$event->send();
$resultList = $event->getResults();
if (is_array($resultList) && !empty($resultList)) {
$customClasses = array();
foreach ($resultList as $eventResult) {
/** @var EventResult $eventResult*/
if ($eventResult->getType() != EventResult::SUCCESS) {
throw new SystemException("Can't add custom tracking class successfully");
}
$params = $eventResult->getParameters();
if (!empty($params) && is_array($params)) {
$customClasses = array_merge($customClasses, $params);
}
}
if (!empty($customClasses)) {
\Bitrix\Main\Loader::registerAutoLoadClasses(null, $customClasses);
$classes = array_merge($customClasses, $classes);
}
}
static::$classes = array_merge(array_keys($classes), static::$classes);
return static::$classes;
}
示例4: isSuccess
public static function isSuccess(\Bitrix\Main\Event $event)
{
foreach ($event->getResults() as $result) {
if ($result->getType() === EventResult::ERROR) {
return false;
}
}
return true;
}
示例5: clearCollection
public function clearCollection()
{
/** @var Main\Entity\Event $event */
$event = new Main\Event('sale', 'OnBeforeCollectionClear', array('COLLECTION' => $this->collection));
$event->send();
/** @var CollectableEntity $item */
foreach ($this->collection as $item) {
$item->delete();
}
}
示例6: onFileRewrite
/**
* Defines if page file should be overridden
*
* @param \Bitrix\Main\Event $event Event.
* @return string|null
*/
public static function onFileRewrite(\Bitrix\Main\Event $event)
{
$path = $event->getParameter('path');
$result = null;
if ($context = Helper::getContext()) {
if ($context['section'] == 'B') {
$result = Helper::getAlternative('page', $path);
}
}
return $result;
}
示例7: handleEvent
/**
* @param \Bitrix\Main\Event $event
* @return mixed
*/
public static function handleEvent(Event $event)
{
$eventData = $event->getParameters();
$eventData = $eventData[0];
$eventName = $eventData['EVENT_NAME'];
$fields = is_array($eventData['C_FIELDS']) ? $eventData['C_FIELDS'] : array();
if (static::isPreventable($eventName, $fields)) {
// error
$result = new EventResult(EventResult::ERROR);
} else {
// success
$result = new EventResult(EventResult::SUCCESS);
}
return $result;
}
示例8: getList
/**
* @return array
*/
public static function getList()
{
$resultList = array();
$event = new Event('sender', 'OnPresetMailBlockList');
$event->send();
foreach ($event->getResults() as $eventResult) {
if ($eventResult->getType() == EventResult::ERROR) {
continue;
}
$eventResultParameters = $eventResult->getParameters();
if (!empty($eventResultParameters)) {
$resultList = array_merge($resultList, $eventResultParameters);
}
}
return $resultList;
}
示例9: testUseHandlerClassParams
public function testUseHandlerClassParams()
{
$eventType = EventType::createByParams("ws.tools", "test");
$this->manager()->subscribe($eventType, $handler = new TestHandler(array('init params')));
$this->manager()->trigger($eventType, array('process params'));
$history = $handler->getHistory();
$this->assertEquals($history[0], array('identity', array('init params'), array('process params')));
$this->assertEquals($history[1], array('process', array('init params'), array('process params')));
$this->manager()->trigger($eventType, array('process2 params'));
$history = $handler->getHistory();
$this->assertEquals($history[3], array('process', array('init params'), array('process2 params')));
$e = new Event("ws.tools", "test", array('process3 params'));
$e->send($this);
$history = $handler->getHistory();
$this->assertEquals($history[5], array('process', array('init params'), array('process3 params')));
}
示例10: __construct
/**
* @param string $eventName
* @param array $parameters
*/
public function __construct($eventName, array $parameters = array())
{
if (FormEvents::BUILD != $eventName && FormEvents::PRE_STORAGE != $eventName && FormEvents::STORAGE != $eventName) {
throw new \InvalidArgumentException('Invalid event name, see FormEvents');
}
parent::__construct(self::MODULE_ID, $eventName, $parameters);
}
示例11: addExtensions
/**
* Добавляет расширения, в том числе расширение для битрикса,
* в котором добавляются нужные глобальные переменные и т.п.
*/
private function addExtensions()
{
$this->getEnvironment()->addExtension(new \Twig_Extension_Debug());
$this->getEnvironment()->addExtension(new BitrixExtension());
$event = new Event('wlbl.twigrix', 'onAddExtensions');
$event->send();
foreach ($event->getResults() as $result) {
if ($result->getType() == EventResult::SUCCESS) {
foreach ($result->getParameters() as $extension) {
if ($extension instanceof \Twig_Extension) {
$this->getEnvironment()->addExtension($extension);
}
}
}
}
}
示例12: __construct
protected function __construct()
{
$event = new Main\Event("main", "OnApplicationsBuildList");
$event->send();
foreach ($event->getResults() as $eventResult) {
$result = $eventResult->getParameters();
if (is_array($result)) {
if (!is_array($result[0])) {
$result = array($result);
}
foreach ($result as $app) {
$this->applications[$app["ID"]] = $app;
}
}
}
Main\Type\Collection::sortByColumn($this->applications, "SORT");
}
示例13: generateInitEvent
/**
* Создается событие для внесения в Twig изменения из проекта
*/
private function generateInitEvent()
{
$eventName = 'onAfterTwigTemplateEngineInited';
$event = new Event('', $eventName, array($this->engine));
$event->send();
if ($event->getResults()) {
foreach ($event->getResults() as $evenResult) {
if ($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS) {
$twig = current($evenResult->getParameters());
if (!$twig instanceof \Twig_Environment) {
throw new \LogicException("Событие '{$eventName}' должно возвращать экземпляр класса '\\Twig_Environment' при успешной отработке");
}
$this->engine = $twig;
}
}
}
}
示例14: onStartUserReplication
public function onStartUserReplication(\Bitrix\Main\Event $event)
{
$parameters = $event->getParameters();
$userId = $parameters[0];
$domain = $parameters[2];
$domainId = getNameByDomain($domain);
if (!$domainId) {
return;
}
$mapper = \Bitrix\Replica\Mapper::getInstance();
$map = $mapper->getByPrimaryValue("b_user.ID", false, $userId);
if (!$map) {
return;
}
$guid = key($map);
$event = array("operation" => "im_status_bind", "guid" => $guid);
\Bitrix\Replica\Log\Client::getInstance()->write(array($domainId), $event);
\Bitrix\Replica\Mapper::getInstance()->add("b_im_status.USER_ID", $userId, $domainId, $event["guid"]);
}
示例15: onExecuteStartWriting
function onExecuteStartWriting(\Bitrix\Main\Event $event)
{
$parameters = $event->getParameters();
$userId = $parameters[0];
$dialogId = $parameters[1] . $parameters[2];
if ($userId > 0) {
if (!\Bitrix\Main\Loader::includeModule('pull')) {
return;
}
\CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS');
if (intval($dialogId) > 0) {
\CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
} elseif (substr($dialogId, 0, 4) == 'chat') {
$arRelation = \CIMChat::GetRelationById(substr($dialogId, 4));
foreach ($arRelation as $rel) {
if ($rel['USER_ID'] == $userId) {
continue;
}
\CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
}
}
}
}