Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Latest commit

 

History

History
60 lines (42 loc) · 1.35 KB

readme.md

File metadata and controls

60 lines (42 loc) · 1.35 KB

Restify

Модуль, который позволяет с легкостью создавать REST API для 1С-Битрикс

Начало работы

Необходимые условия окружения

Для запуска проекта в системе должны быть установлены:

  • PHP >= 7
  • Composer

Установка

composer require spaceonfire/restify

Examples

Events

API output transformation

<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';

use Bitrix\Main\Event;
use Bitrix\Main\EventManager;
use Emonkak\HttpException\InternalServerErrorHttpException;

EventManager::getInstance()->addEventHandler(
	'spaceonfire.restify',
	'transform',
	'modifyStatusCode'
);

function throw500() {
	throw new InternalServerErrorHttpException();
}

function modifyStatusCode(Event $event) {
	$params = $event->getParameters();
	$params['statusCode'] = 500;
}

Build full path to image in FileFormatter

use Bitrix\Main\Event;
use Bitrix\Main\EventManager;

EventManager::getInstance()->addEventHandler('spaceonfire.restify', 'OnFileFormatter', function(Event $event) {
	$params = $event->getParameters();
	$params['data']['SRC'] = $_SERVER['REQUEST_SCHEME'] . '://' . (env('DOMAIN') ?: $_SERVER['HTTP_HOST']) . $params['data']['SRC'];
});