/*
Принимает отладочное сооющение

@param string тип сообщения
@param string сообщение
@return void
515279
public function debug($mode, $str)
    {
    	if (!$this->_debugger) return;
    	$this->_debugger->log($str, $mode);
    }
411968
public function flush()
  {
    // God, PHP really has some esoteric ways of doing simple things.
    $host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');

    $headers = array();
    $defaultHeaders = array('Host' => $host,
                            'Accept' => 'application/x-thrift',
                            'User-Agent' => 'PHP/THttpClient',
                            'Content-Type' => 'application/x-thrift',
                            'Content-Length' => TStringFuncFactory::create()->strlen($this->buf_));
    foreach (array_merge($defaultHeaders, $this->headers_) as $key => $value) {
        $headers[] = "$key: $value";
    }

    $options = array('method' => 'POST',
                     'header' => implode("\r\n", $headers),
                     'max_redirects' => 1,
                     'content' => $this->buf_);
    if ($this->timeout_ > 0) {
      $options['timeout'] = $this->timeout_;
    }
    $this->buf_ = '';

    $contextid = stream_context_create(array('http' => $options));
    $this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid);

    // Connect failed?
    if ($this->handle_ === FALSE) {
      $this->handle_ = null;
      $error = 'THttpClient: Could not connect to '.$host.$this->uri_;
      throw new TTransportException($error, TTransportException::NOT_OPEN);
    }
  }
381651
function tpl_key_data($attrib)
    {
        $out   = '';
        $table = new html_table(array('cols' => 2));

        // Key user ID
        $table->add('title', $this->enigma->gettext('keyuserid'));
        $table->add(null, rcube::Q($this->data->name));

        // Key ID
        $table->add('title', $this->enigma->gettext('keyid'));
        $table->add(null, $this->data->subkeys[0]->get_short_id());

        // Key type
        $keytype = $this->data->get_type();
        if ($keytype == enigma_key::TYPE_KEYPAIR) {
            $type = $this->enigma->gettext('typekeypair');
        }
        else if ($keytype == enigma_key::TYPE_PUBLIC) {
            $type = $this->enigma->gettext('typepublickey');
        }
        $table->add('title', $this->enigma->gettext('keytype'));
        $table->add(null, $type);

        // Key fingerprint
        $table->add('title', $this->enigma->gettext('fingerprint'));
        $table->add(null, $this->data->subkeys[0]->get_fingerprint());

        $out .= html::tag('fieldset', null,
            html::tag('legend', null,
                $this->enigma->gettext('basicinfo')) . $table->show($attrib));

        // Subkeys
        $table = new html_table(array('cols' => 5, 'id' => 'enigmasubkeytable', 'class' => 'records-table'));

        $table->add_header('id', $this->enigma->gettext('subkeyid'));
        $table->add_header('algo', $this->enigma->gettext('subkeyalgo'));
        $table->add_header('created', $this->enigma->gettext('subkeycreated'));
        $table->add_header('expires', $this->enigma->gettext('subkeyexpires'));
        $table->add_header('usage', $this->enigma->gettext('subkeyusage'));

        $now         = time();
        $date_format = $this->rc->config->get('date_format', 'Y-m-d');
        $usage_map   = array(
            enigma_key::CAN_ENCRYPT      => $this->enigma->gettext('typeencrypt'),
            enigma_key::CAN_SIGN         => $this->enigma->gettext('typesign'),
            enigma_key::CAN_CERTIFY      => $this->enigma->gettext('typecert'),
            enigma_key::CAN_AUTHENTICATE => $this->enigma->gettext('typeauth'),
        );

        foreach ($this->data->subkeys as $subkey) {
            $algo = $subkey->get_algorithm();
            if ($algo && $subkey->length) {
                $algo .= ' (' . $subkey->length . ')';
            }

            $usage = array();
            foreach ($usage_map as $key => $text) {
                if ($subkey->usage & $key) {
                    $usage[] = $text;
                }
            }

            $table->add('id', $subkey->get_short_id());
            $table->add('algo', $algo);
            $table->add('created', $subkey->created ? $this->rc->format_date($subkey->created, $date_format, false) : '');
            $table->add('expires', $subkey->expires ? $this->rc->format_date($subkey->expires, $date_format, false) : $this->enigma->gettext('expiresnever'));
            $table->add('usage', implode(',', $usage));
            $table->set_row_attribs($subkey->revoked || ($subkey->expires && $subkey->expires < $now) ? 'deleted' : '');
        }

        $out .= html::tag('fieldset', null,
            html::tag('legend', null,
                $this->enigma->gettext('subkeys')) . $table->show());

        // Additional user IDs
        $table = new html_table(array('cols' => 2, 'id' => 'enigmausertable', 'class' => 'records-table'));

        $table->add_header('id', $this->enigma->gettext('userid'));
        $table->add_header('valid', $this->enigma->gettext('uservalid'));

        foreach ($this->data->users as $user) {
            $username = $user->name;
            if ($user->comment) {
                $username .= ' (' . $user->comment . ')';
            }
            $username .= ' <' . $user->email . '>';

            $table->add('id', rcube::Q(trim($username)));
            $table->add('valid', $this->enigma->gettext($user->valid ? 'valid' : 'unknown'));
            $table->set_row_attribs($user->revoked || !$user->valid ? 'deleted' : '');
        }

        $out .= html::tag('fieldset', null,
            html::tag('legend', null,
                $this->enigma->gettext('userids')) . $table->show());

        return $out;
    }
1049502
public function handle($request)
    {
        // смотрим метод, к которому пытаются обратиться
        $namespace = $request->server->namespace;
        $method = $request->call->method;

        if (!empty($request->call->endpoint) && !empty($request->call->action)) {
            $namespace = $request->server->namespace . studly_case($request->call->endpoint) . '\\';
            $controllerName = $request->call->action;
        } elseif (!empty($request->call->endpoint)) {
            $controllerName = $request->call->endpoint;
        } else {
            $methodCall = $request->call->method;

            // парсим имя метода
            $methodArray = explode('_', $methodCall);

            // если имя вызываемого метода без разделителя - значит ищем его в базовом классе
            if (\count($methodArray) === 1) {
                $controllerName = $request->server->controller;
                $method = $methodCall;
            } else {
                $controllerName = $methodArray[0];
                unset($methodArray[0]);
                $method = camel_case(implode('_', $methodArray));
            }

        }

        $controllerName = $namespace . studly_case($controllerName . $request->server->postfix);

        // если нет такого контроллера или метода
        if (!class_exists($controllerName)) {
            throw new JsonRpcException(JsonRpcException::CODE_METHOD_NOT_FOUND);
        }

        $controller = app($controllerName);

        if (!\is_callable([$controller, $method])) {
            throw new JsonRpcException(JsonRpcException::CODE_METHOD_NOT_FOUND);
        }

        $request->controller = $controller;
        $request->method = $method;
        $request->params = !empty($request->call->params) ? array_values((array)$request->call->params) : [];

        return true;
    }
705649
static function handleInclude( &$textElements, &$uri, $tpl, $rootNamespace, $name )
    {
        $tpl->processURI( $uri, true, $extraParameters, $textElements, $name, $name );
    }
1303161
public static function report($st)
	{
		if ( !isset(self::$cli) )
		{
			global $argv;
			self::$cli = isset($argv) ? 1 : false;
		}
		if ( self::$cli )
		{
			if ( \is_string($st) )
				echo $st."\n";
			else
				var_dump($st)."\n";
		}
		else
		{
			if ( \is_string($st) )
				array_push(self::$info,$st);
			else
				array_push(self::$info,print_r($st,true));
		}
	}
29824
public function hook($method, $callback = null)
    {
        if (is_array($method)) {
            $this->hook = array_merge($this->hook, $method);
        } else {
            $this->hook[$method] = $callback;
        }
    }
565761
public function __HANDLER($nav = 0, $page = 1)
    {
        // Render view
        m()->view('index')
            ->html(CMSField::renderTable($nav, $page))
            ->title('Дополнительные поля');
    }
210966
function process( $tpl, &$text, $nspace, $current_nspace )
    {
        foreach( array_keys( $this->Children ) as $key )
        {
            $this->Children[$key]->process( $tpl, $text, $nspace, $current_nspace );
        }
    }
201602
public function run(): void
    {
        try {
            /** @var \Ffcms\Core\Arch\Controller $callClass */
            $callClass = $this->getCallbackClass();
            $callMethod = 'action' . self::$Request->getAction();
            $arguments = self::$Request->getArguments();

            // check if callback method (action) is exist in class object
            if (!method_exists($callClass, $callMethod)) {
                throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"');
            }

            // check if method arguments counts equals passed count
            $requiredArgCount = $this->getMethodRequiredArgCount($callClass, $callMethod);

            // compare method arg count with passed
            if (count($arguments) < $requiredArgCount) {
                throw new NotFoundException(__('Arguments for method %method% is not enough. Expected: %required%, got: %current%.', [
                    'method' => $callMethod,
                    'required' => $requiredArgCount,
                    'current' => count($arguments)
                ]));
            }

            // make callback call to action in controller and get response
            $response = call_user_func_array([$callClass, $callMethod], $arguments);

            // if no response - throw 404 not found
            if (!$response) {
                throw new NotFoundException('Page not found: 404 error');
            }
        } catch (\Exception $e) {
            // check if exception is system-based throw
            if ($e instanceof TemplateException) {
                $response = $e->display();
            } else { // or hook exception to system based :)))
                if (App::$Debug) {
                    $msg = $e->getMessage() . $e->getTraceAsString();
                    $response = (new NativeException($msg))->display();
                } else {
                    $response = (new NativeException($e->getMessage()))->display();
                }
            }
        }

        // set full rendered content to response builder
        self::$Response->setContent($response);
        // echo full response to user via symfony http foundation
        self::$Response->send();
    }
477005
public function append($resource)
    {
        parent::append($resource);
        if ($this->totalCount !== null) {
            $this->setTotalCount($this->totalCount);
        }
    }
1142637
function field_prep(&$item)
    {
        $item['type'] = strtolower($item['type']);
        # Метка
        if (!isset($item['label'])) $item['label'] = '';
        # Подсказка
        if (isset($item['hint'])) $item['label'] = '<span class="hint" title="'.$item['hint'].'">'.$item['label'].'</span>';
        # Маска значения
        if (isset($item['pattern']) && isset($item['name']))
            $this->validator .= "
				if (!form.".$item['name'].".value.match(".$item['pattern'].")) {
					alert('".(isset($item['errormsg'])?$item['errormsg']:sprintf(errFormPatternError, $item['name'], $item['pattern']))."');
					result = false;
					form.".$item['name'].".select();
				} else ";
        # Значение
        $item['value'] = isset($item['value']) ? $item['value']
            : (isset($item['name']) && isset($this->values[$item['name']]) ? $this->values[$item['name']]
                : (isset($item['default']) ? $item['default']
                    : '' )
            );
        # ID
        if (!isset($item['id'])) $item['id'] = '';
        # Элемент отключен
        if (!isset($item['disabled'])) $item['disabled'] = '';
        # Комментарий
        $item['comment'] = isset($item['comment']) ? ' '.$item['comment'] : '';
        # Стили
        $item['style'] = isset($item['style']) ? explode(';', $item['style']) : array();
        # Классы
        $item['class'] = isset($item['class']) ? explode(' ', $item['class']) : array();
        # Дополнительно
        if (!isset($item['extra'])) $item['extra'] = '';
    }
616554
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
    {
        $operatorValue = str_replace( "\n",
                                      "<br />",
                                      $operatorValue );
    }
1151338
function modify( $tpl, $operatorName, $operatorParameters,
                     $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
    {
        $functionName = $namedParameters['function_name'];
        $functionParameters = $namedParameters['function_parameters'];

        if ( $operatorName == $this->Fetch )
        {
            $moduleName = $namedParameters['module_name'];
            $result = eZFunctionHandler::execute( $moduleName, $functionName, $functionParameters );
            $operatorValue = $result;
        }
        else if ( $operatorName == $this->FetchAlias )
        {
            $result = eZFunctionHandler::executeAlias( $functionName, $functionParameters );
            $operatorValue = $result;
        }
    }
4035
public function show($tpl = "")
    {
        if (!empty($tpl)) {
            $this->display($tpl);
        } else {
            $this->display(strtolower($this->apiClassName) .'/'.strtolower($this->action) . '.tpl');
        }
        exit();
    }
221560
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters, $placement )
    {
        $phpname = $this->PHPNames[$operatorName];
        if ( $value !== null )
            $operand = $value;
        else
            $operand = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
        $value = $phpname( $operand );
    }
1194338
public function add()
    {
        $obj = new \CIBlockType();
        if (!$obj->Add($this->getFieldsWithDefault())) {
            throw new \Exception($obj->LAST_ERROR);
        }

        Logger::log("Добавлен тип инфоблока {$this->fields['ID']}", Logger::COLOR_GREEN);
    }