Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jan 24, 2017
2 parents 59b3e2e + ebab31a commit 6dd6b93
Show file tree
Hide file tree
Showing 49 changed files with 2,176 additions and 1,410 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Tools to use API as ActiveRecord for Yii2
@link https://github.com/hiqdev/yii2-hiart
@package yii2-hiart
@license BSD-3-Clause
@copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
@copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
EOF;

return PhpCsFixer\Config::create()
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2015-2016, HiQDev (http://hiqdev.com/)
Copyright © 2015-2017, HiQDev (http://hiqdev.com/)
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
72 changes: 63 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,88 @@ To use this extension, configure hiart component in your application config:
```php
'components' => [
'hiart' => [
'class' => 'hiqdev\hiart\Connection',
'config' => [
'base_uri' => 'https://api.site.com/',
],
'class' => \hiqdev\hiart\rest\Connection::class,
'requestClass' => \hiqdev\hiart\curl\Request::class,
'baseUri' => 'https://site.com/api/v3/',
],
],
```

Note three main options:

- `class` specifies class that actually implements API to be accessed, **REST** in this case
- `requestClass` specifies transport implementation to be used, **cURL** in this case
- `baseUri` specifies starting point of the API

Available transports are:

- [PHP streams](http://php.net/manual/en/book.stream.php), **default**, included in this package
- [cURL](http://php.net/manual/en/book.curl.php), included in this package
- [Guzzle](https://github.com/guzzle/guzzle), provided with [yii2-hiart-guzzle](https://github.com/hiqdev/yii2-hiart-guzzle)
- [yii2-httpclient](https://github.com/yiisoft/yii2-httpclient), provided with [yii2-hiart-httpclient](https://github.com/hiqdev/yii2-hiart-httpclient)

You can implement your own transport, it's not difficult see available implementations.
All you need is to create two classes:
It can be even not HTTP based.

There are `QueryBuilder`s for:

- Basic [REST](https://en.wikipedia.org/wiki/Representational_state_transfer), included in this package
- [GitHub API](https://developer.github.com/v3/), provided with [yii2-hiart-github](https://github.com/hiqdev/yii2-hiart-github)
- [HiPanel API](https://hipanel.com/), provided with [hipanel-hiart](https://github.com/hiqdev/hipanel-hiart)

You can implement your own API.
Basically all you need is to create your QueryBuilder with these methods:

- `buildMethod(Query $query)`
- `buildHeaders(Query $query)`
- `buildUri(Query $query)`
- `buildQueryParams(Query $query)`
- `buildBody(Query $query)`
- `buildFormParams(Query $query)`

See available implementations and create issues on GitHub.

## Usage

Define your Model
Define your Model:

```php
class MyModel extends \hiqdev\hiart\ActiveRecord
class User extends \hiqdev\hiart\ActiveRecord
{
public function attributes()
public function rules()
{
return ['id', 'name', 'else'];
return [
['id', 'integer', 'min' => 1],
['login', 'string', 'min' => 2, 'max' => 32],
];
}
}
```

Note that you use general `hiqdev\hiart\ActiveRecord` class not specific for certain API.
API is specified in connection options and you don't need to change model classes when
you change API.

Then you just use your models same way as DB ActiveRecord models.

```php
$user = new User();
$user->login = 'sol';

$user->save();

$admins = User::find()->where(['type' => User::ADMIN_TYPE])->all();
```

Basically all features of Yii ActiveRecords work if your API provides them.

## License

This project is released under the terms of the BSD-3-Clause [license](LICENSE).
Read more [here](http://choosealicense.com/licenses/bsd-3-clause).

Copyright © 2015-2016, HiQDev (http://hiqdev.com/)
Copyright © 2015-2017, HiQDev (http://hiqdev.com/)

## Acknowledgments

Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@
{
"name": "Dmitry Naumenko",
"role": "Lead backend developer",
"email": "silverfire@hiqdev.com",
"email": "d.naumenko.a@gmail.com",
"homepage": "http://silverfire.me/"
},
{
"name": "Andrey Klochok",
"role": "Lead frontend developer",
"email": "tafid@hiqdev.com",
"email": "andreyklochok@gmail.com",
"homepage": "http://hiqdev.com/"
},
{
"name": "Yuriy Myronchuk",
"role": "QA Lead",
"email": "bladeroot@hiqdev.com",
"email": "bladeroot@gmail.com",
"homepage": "http://hiqdev.com/"
}
],
"require": {
"yiisoft/yii2": "~2.0",
"guzzlehttp/guzzle": "6.*"
"yiisoft/yii2": "~2.0"
},
"require-dev": {
"hiqdev/yii2-hiart-github": "dev-master",
"hiqdev/hidev-php": "<2.0",
"hiqdev/hidev-hiqdev": "<2.0"
},
Expand All @@ -65,7 +65,8 @@
"config-plugin": {
"params": "src/config/params.php",
"common": "src/config/common.php",
"hisite": "src/config/hisite.php"
"hisite": "src/config/hisite.php",
"hidev": "src/config/hidev.php"
}
},
"repositories": [
Expand Down
42 changes: 38 additions & 4 deletions docs/readme/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,44 @@ To use this extension, configure hiart component in your application config:
```php
'components' => [
'hiart' => [
'class' => 'hiqdev\hiart\Connection',
'config' => [
'base_uri' => 'https://api.site.com/',
],
'class' => \hiqdev\hiart\rest\Connection::class,
'requestClass' => \hiqdev\hiart\curl\Request::class,
'baseUri' => 'https://site.com/api/v3/',
],
],
```

Note three main options:

- `class` specifies class that actually implements API to be accessed, **REST** in this case
- `requestClass` specifies transport implementation to be used, **cURL** in this case
- `baseUri` specifies starting point of the API

Available transports are:

- [PHP streams](http://php.net/manual/en/book.stream.php), **default**, included in this package
- [cURL](http://php.net/manual/en/book.curl.php), included in this package
- [Guzzle](https://github.com/guzzle/guzzle), provided with [yii2-hiart-guzzle](https://github.com/hiqdev/yii2-hiart-guzzle)
- [yii2-httpclient](https://github.com/yiisoft/yii2-httpclient), provided with [yii2-hiart-httpclient](https://github.com/hiqdev/yii2-hiart-httpclient)

You can implement your own transport, it's not difficult see available implementations.
All you need is to create two classes:
It can be even not HTTP based.

There are `QueryBuilder`s for:

- Basic [REST](https://en.wikipedia.org/wiki/Representational_state_transfer), included in this package
- [GitHub API](https://developer.github.com/v3/), provided with [yii2-hiart-github](https://github.com/hiqdev/yii2-hiart-github)
- [HiPanel API](https://hipanel.com/), provided with [hipanel-hiart](https://github.com/hiqdev/hipanel-hiart)

You can implement your own API.
Basically all you need is to create your QueryBuilder with these methods:

- `buildMethod(Query $query)`
- `buildHeaders(Query $query)`
- `buildUri(Query $query)`
- `buildQueryParams(Query $query)`
- `buildBody(Query $query)`
- `buildFormParams(Query $query)`

See available implementations and create issues on GitHub.
27 changes: 23 additions & 4 deletions docs/readme/Usage.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
Define your Model
Define your Model:

```php
class MyModel extends \hiqdev\hiart\ActiveRecord
class User extends \hiqdev\hiart\ActiveRecord
{
public function attributes()
public function rules()
{
return ['id', 'name', 'else'];
return [
['id', 'integer', 'min' => 1],
['login', 'string', 'min' => 2, 'max' => 32],
];
}
}
```

Note that you use general `hiqdev\hiart\ActiveRecord` class not specific for certain API.
API is specified in connection options and you don't need to change model classes when
you change API.

Then you just use your models same way as DB ActiveRecord models.

```php
$user = new User();
$user->login = 'sol';

$user->save();

$admins = User::find()->where(['type' => User::ADMIN_TYPE])->all();
```

Basically all features of Yii ActiveRecords work if your API provides them.
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<testsuite name="Unit Test Suite">
<directory>./tests/unit/</directory>
</testsuite>
<testsuite name="GitHub functional">
<directory>./vendor/hiqdev/hidev-hiart/tests/functional/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
Expand Down
Loading

0 comments on commit 6dd6b93

Please sign in to comment.