diff --git a/.gitignore b/.gitignore index f5140f0e..6ae5ed5a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ composer.lock tools/.env.local tools/logs examples/logs +*.log .env.local \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c8ad878..20495c42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # bitrix24-php-sdk change log +## 2.0-beta.2 — 1.04.2024 + +### Added +### Changed +* updated [dependencies versions](https://github.com/mesilov/bitrix24-php-sdk/issues/373): + * require + * `psr/log` `1.4.0` → `3.0.*` + * `moneyphp/money` `4.3.*` → `4.5.*` + * require-dev + * `monolog/monolog` `2.9.*` → `3.5.*` + * `phpunit/phpunit` `10.5.*` → `11.0.*` +### Bugfix +### etc + ## 2.0-beta.1 — 18.02.2024 ### Added diff --git a/README.md b/README.md index 162cf165..1b68984d 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Domain core events: API - level features - [x] Auto renew access tokens -- [ ] List queries with «start=-1» support +- [x] List queries with «start=-1» support - [ ] offline queues Performance improvements 🚀 @@ -67,7 +67,6 @@ Low-level tools to devs: - Reliable: - test coverage: unit, integration, contract - typical examples typical for different modes of operation and they are optimized for memory \ performance - ## Architecture ### Abstraction layers @@ -98,6 +97,30 @@ Help bitrix24-php-sdk by [boosty.to/bitrix24-php-sdk](https://boosty.to/bitrix24 Add `"mesilov/bitrix24-php-sdk": "2.x"` to `composer.json` of your application. Or clone repo to your project. +## Examples +### Work with webhook +```php +declare(strict_types=1); + +use Bitrix24\SDK\Services\ServiceBuilderFactory; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcher; + +require_once 'vendor/autoload.php'; + +$webhookUrl = 'INSERT_HERE_YOUR_WEBHOOK_URL'; + +$log = new Logger('bitrix24-php-sdk'); +$b24ServiceFactory = new ServiceBuilderFactory(new EventDispatcher(), $log); + +// init bitrix24-php-sdk service +$b24Service = $b24ServiceFactory->initFromWebhook($webhookUrl); + +// work with interested scope +var_dump($b24Service->getMainScope()->main()->getCurrentUserProfile()->getUserProfile()); +var_dump($b24Service->getCRMScope()->lead()->list([],[],['ID','TITLE'])->getLeads()[0]->TITLE); +``` + ## Tests Tests locate in folder `tests` and we have two test types. diff --git a/composer.json b/composer.json index 0aba0659..4d19c130 100644 --- a/composer.json +++ b/composer.json @@ -25,20 +25,20 @@ "ext-bcmath": "*", "ext-curl": "*", "ext-intl": "*", - "psr/log": "1.1.*", + "psr/log": "^2 || ^3", "fig/http-message-util": "1.1.*", - "ramsey/uuid": "4.7.*", - "moneyphp/money": "4.3.*", - "symfony/http-client": "7.0.*", - "symfony/http-client-contracts": "3.4.*", - "symfony/http-foundation": "7.0.*", - "symfony/event-dispatcher": "7.0.*", - "symfony/uid": "7.0.*" + "ramsey/uuid": "^3 ||^4", + "moneyphp/money": "^3 || ^4", + "symfony/http-client": "^6 || ^7", + "symfony/http-client-contracts": "^2 || ^3", + "symfony/http-foundation": "^6 || ^7", + "symfony/event-dispatcher": "^6 || ^7", + "symfony/uid": "^6 || ^7" }, "require-dev": { - "monolog/monolog": "2.9.*", + "monolog/monolog": "3.5.*", "phpstan/phpstan": "1.10.*", - "phpunit/phpunit": "10.5.*", + "phpunit/phpunit": "11.0.*", "symfony/console": "7.0.*", "symfony/dotenv": "7.0.*", "symfony/debug-bundle": "7.0.*", diff --git a/examples/webhook/.env b/examples/webhook/.env new file mode 100644 index 00000000..1355fb8e --- /dev/null +++ b/examples/webhook/.env @@ -0,0 +1,5 @@ +# bitrix24 webhook url +BITRIX24_WEBHOOK_URL= +# monolog +LOG_LEVEL=100 +LOG_FILE_NAME=bitrix24-php-sdk.log diff --git a/examples/webhook/composer.json b/examples/webhook/composer.json new file mode 100644 index 00000000..03105bc5 --- /dev/null +++ b/examples/webhook/composer.json @@ -0,0 +1,20 @@ +{ + "name": "mesilov/bitrix24-php-sdk-webhook-example", + "description": "Example for work with bitrix24-php-sdk via webhook", + "minimum-stability": "stable", + "license": "proprietary", + "authors": [ + { + "name": "Maksim Mesilov", + "email": "mesilov.maxim@gmail.com" + } + ], + "require": { + "mesilov/bitrix24-php-sdk": "dev-371-publish-b24-php-sdk-beta-2", + "monolog/monolog": "3.5.*", + "symfony/dotenv": "7.0.*" + }, + "require-dev": { + "roave/security-advisories": "dev-latest" + } +} \ No newline at end of file diff --git a/examples/webhook/example.php b/examples/webhook/example.php new file mode 100644 index 00000000..bc3098ac --- /dev/null +++ b/examples/webhook/example.php @@ -0,0 +1,30 @@ +loadEnv('.env'); +$webhookUrl = $_ENV['BITRIX24_WEBHOOK_URL']; + +// configure logger for debug queries +$log = new Logger('bitrix24-php-sdk'); +$log->pushHandler(new StreamHandler($_ENV['LOG_FILE_NAME'], (int)$_ENV['LOG_LEVEL'])); +$log->pushProcessor(new MemoryUsageProcessor(true, true)); +$log->pushProcessor(new IntrospectionProcessor()); + +// create factory for build service from multiple sources: webhook, request, bitrix24 account with oauth2.0 tokens +$b24ServiceFactory = new ServiceBuilderFactory(new EventDispatcher(), $log); +// init bitrix24-php-sdk service with webhook credentials +$b24Service = $b24ServiceFactory->initFromWebhook($webhookUrl); + +$deal = $b24Service->getCRMScope()->deal()->get(1)->deal(); +var_dump($deal->TITLE); \ No newline at end of file