-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
469 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Change Log | ||
|
||
## 0.3.4 - 2016-09-01 | ||
|
||
### Changed | ||
|
||
- Change MaxDataServiceVersion to 3.0 in requests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Создание объектов | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Удаление объектов | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Документы | ||
|
||
TODO | ||
|
||
## Service Documents | ||
|
||
[Service Document](http://www.odata.org/documentation/odata-version-2-0/atom-format/#ServiceDocuments) | ||
lists available collections (which are grouped to *workspaces*). | ||
|
||
```php | ||
/** @var ServiceDocument $document */ | ||
foreach ($document->getWorkspaces() as $workspace) { | ||
echo 'Title: ' . $workspace->getTitle() . PHP_EOL; | ||
foreach ($workspace->getCollections() as $collection) { | ||
echo ' Title: ' . $collection->getTitle() . PHP_EOL; | ||
echo ' Href: ' . $collection->getHref() . PHP_EOL; | ||
} | ||
} | ||
``` | ||
|
||
## Metadata Documents | ||
|
||
[Metadata Document](http://www.odata.org/documentation/odata-version-2-0/overview/#ServiceMetadataDocument) | ||
|
||
TODO | ||
|
||
## Collections of Entries | ||
|
||
Collections represent a set of Entries. In OData, Collections are represented as Atom feeds, with | ||
one Atom entry for each Entry within the Collection. | ||
|
||
## Entries | ||
|
||
In OData, Entries are represented as Atom entries. | ||
|
||
```php | ||
//... | ||
|
||
$uri = new Uri(); | ||
$uri | ||
->collection('Categories') | ||
->item('123'); | ||
|
||
$document = $service->sendRequest('GET', $uri); | ||
if (!$document instanceof EntryDocument) { | ||
throw new \RuntimeException; | ||
} | ||
$entry = $document->getEntry(); // Instance of Mekras\OData\Client\Element\Entry | ||
``` | ||
|
||
Entry meta data can be accessed via normal `Mekras\Atom\Element\Entry` methods: | ||
|
||
```php | ||
echo 'Title: ' . $entry->getTitle() . PHP_EOL; | ||
echo 'ID: ' . $entry->getId() . PHP_EOL; | ||
echo 'Updated: ' . $entry->getUpdated()->format('d.m.y H:i:s') . PHP_EOL; | ||
``` | ||
|
||
Entry properties can be accessed via `getContent` method: | ||
|
||
```php | ||
$properties = $entry->getContent(); | ||
echo ' Id: ' . $properties['Id'] . PHP_EOL; | ||
echo ' Hostname: ' . $properties['HostName'] . PHP_EOL; | ||
echo ' Operations: ' . $properties['Operations'] . PHP_EOL; | ||
``` | ||
|
||
Or directly as array elements: | ||
|
||
```php | ||
echo ' Id: ' . $entry['Id'] . PHP_EOL; | ||
echo ' Hostname: ' . $entry['HostName'] . PHP_EOL; | ||
echo ' Operations: ' . $entry['Operations'] . PHP_EOL; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# OData client-side library | ||
|
||
TODO | ||
|
||
--- | ||
|
||
[[русский](index.ru.md)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Клиентская библиотека OData | ||
|
||
1. [Установка](install.ru.md) | ||
2. [Начало работы](intro.ru.md) | ||
3. [Составление адресов](uri.ru.md) | ||
4. [Запросы и ответы](requests.ru.md) | ||
5. [Документы](documents.ru.md) | ||
6. [Получение объектов](read.ru.md) | ||
7. [Создание объектов](create.ru.md) | ||
8. [Изменение объектов](update.ru.md) | ||
9. [Удаление объектов](delete.ru.md) | ||
|
||
**Приложения** | ||
|
||
- [Класс Service](service.ru.md) | ||
|
||
--- | ||
|
||
[[English](index.en.md)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Установка | ||
|
||
Установка производится с помощью [Composer](https://getcomposer.org/). Однако перед установкой надо | ||
добавить в проект некоторые зависимости. | ||
|
||
Для работы с HTTP используются библиотеки [PHP-HTTP](http://php-http.org/). Поэтому надо | ||
подключить пакет, предоставляющий | ||
[php-http/client-implementation](https://packagist.org/providers/php-http/client-implementation), | ||
например [php-http/curl-client](https://packagist.org/packages/php-http/curl-client). Для этого | ||
в папке проекта выполните: | ||
|
||
composer require php-http/curl-client | ||
|
||
Подробнее о доступных клиентах можно прочитать на сайте | ||
[PHP-HTTP](http://php-http.org/en/latest/clients.html). | ||
|
||
Теперь можно установить `odata-client`: | ||
|
||
composer require mekras/odata-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Введение | ||
|
||
Первым делом вам надо создать экземпляр `Service` — представляющий службу OData, заданную | ||
определённым URI. | ||
|
||
```php | ||
use Mekras\OData\Client\Service; | ||
|
||
$service = new Service( | ||
'http://example.com/odata/', | ||
$httpClient, // Http\Client\HttpClient | ||
$messageFactory // Http\Message\MessageFactory | ||
); | ||
``` | ||
|
||
Теперь можно выполнить первый запрос к службе: | ||
|
||
```php | ||
use Mekras\OData\Client\Document\EntryDocument; | ||
use Mekras\OData\Client\OData; | ||
use Mekras\OData\Client\URI\Uri; | ||
|
||
$uri = new Uri(); | ||
$uri | ||
->collection('Products') | ||
->item(1); | ||
|
||
$document = $service->sendRequest(OData::GET, $uri); | ||
|
||
if (!$document instanceof EntryDocument) { | ||
die("Not an entry!\n"); | ||
} | ||
|
||
$entry = $document->getEntry(); | ||
printf("Id: %s\nRelease: %s\n", $entry['ID'], $entry['Price']); | ||
``` | ||
|
||
Полный пример: [example/get_entry.php](example/get_entry.php). | ||
|
||
Разберём пример подробно. | ||
|
||
```php | ||
$uri = new Uri(); | ||
$uri | ||
->collection('Products') | ||
->item(1); | ||
``` | ||
|
||
Здесь мы составляем адрес запрашиваемого документа. Результат будет соответствовать «/Products(1)». | ||
|
||
Подробнее класс `Uri` рассматривается в разделе [Составление адресов](uri.ru.md). | ||
|
||
```php | ||
$document = $service->sendRequest(OData::GET, $uri); | ||
|
||
if (!$document instanceof EntryDocument) { | ||
die("Not an entry!\n"); | ||
} | ||
``` | ||
|
||
Запрашиваем у службы OData документ (`OData::GET`) расположенный по составленному нами ранее адресу. | ||
Получив ответ, проверяем, что это документ, содержащий одну запись (`EntryDocument`). | ||
|
||
Подробнее метод `sendRequest` рассматривается в разделе [Класс Service](service.ru.md). | ||
|
||
```php | ||
$entry = $document->getEntry(); | ||
printf("Id: %s\nRelease: %s\n", $entry['ID'], $entry['Price']); | ||
``` | ||
|
||
Здесь мы получаем из документа запись и выводим некоторые её свойства. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Получение объектов | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Запросы и ответы | ||
|
||
TODO | ||
|
Oops, something went wrong.