T
T
Timur Kalimullin2015-06-07 15:52:10
PHP
Timur Kalimullin, 2015-06-07 15:52:10

How to make a Callback in the class method of your module for 1C-Bitrix?

Good afternoon,
for the module used by users from the marketplace (1C-Bitrix), it is necessary to add the ability to change, if necessary, the results of the class methods.
To implement the callback, I used the call_user_func function. Perhaps 1C-Bitrix already has its own Events that can be registered and assigned to your module?
At the moment the code has the following structure:

class myClass {
  public function import()
  {
    $arResult = array();

    $arData = array(
      'result1',
      'result2',
      'result3',
    );

    foreach($arData AS $v)
    {
      $arResult[] = 'Строка: '.$v;
    }

    if(function_exists('call_import'))
      $arResult = call_user_func('call_import', $arResult);
    
    return $arResult;
  }
}

function call_import($arData = array())
{
  $arResult = array();
  foreach($arData AS $v)
  {
    $arResult[] = $v.' что то изменили';
  }
  return $arResult;
}

this method will allow the user to create his own call_import function and change the result of the import method.
To what extent is this decision correct?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-06-07
@ZetRider

Of course, you need to use standard events .

A
Andrey Burov, 2015-06-07
@BuriK666

class myClass {
  public function import($callback = null)
  {
    $arResult = array();

    $arData = array(
      'result1',
      'result2',
      'result3',
    );

    foreach($arData AS $v)
    {
      $arResult[] = 'Строка: '.$v;
    }

    if (is_callable($callback)) {
        call_user_func($callback, $arResult);
    }
    
    return $arResult;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question