Skip to content
This repository was archived by the owner on Jan 28, 2024. It is now read-only.

Commit dcc297f

Browse files
committed
v2-beta
0 parents  commit dcc297f

File tree

198 files changed

+23955
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+23955
-0
lines changed

.bowerrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory" : "vendor/bower-asset"
3+
}

.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# yii console command
2+
/yii
3+
/yii_test
4+
5+
# phpstorm project files
6+
.idea
7+
8+
# netbeans project files
9+
nbproject
10+
11+
# zend studio for eclipse project files
12+
.buildpath
13+
.project
14+
.settings
15+
16+
# windows thumbnail cache
17+
Thumbs.db
18+
19+
# composer vendor dir
20+
/vendor
21+
22+
# composer itself is not needed
23+
composer.phar
24+
25+
# Mac DS_Store Files
26+
.DS_Store
27+
28+
# phpunit itself is not needed
29+
phpunit.phar
30+
# local phpunit config
31+
/phpunit.xml
32+
33+
# todo notes
34+
/todo.todo
35+
/todo.txt

LICENSE.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2019, Gani Georgiev
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
Presentator v2 REST API [![Yii2](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](http://www.yiiframework.com/)
2+
======================================================================
3+
4+
Presentator v2 REST API server implementation, written in PHP and based on [Yii2](https://www.yiiframework.com/).
5+
6+
**Detailed API reference could be found here - [https://presentator.io/docs](https://presentator.io/docs).**
7+
8+
- [Requirements](#requirements)
9+
- [Installation](#installation)
10+
- [Development](#development)
11+
12+
> **This repository is READ-ONLY.**
13+
> **Report issues and send pull requests in the [main Presentator repository](https://github.com/presentator/presentator/issues).**
14+
15+
16+
## Requirements
17+
18+
- Apache/Nginx HTTP server
19+
20+
- SQL database (MySQL/MariadDB/PostgreSQL)
21+
22+
- PHP 7.1+ with the following extensions:
23+
24+
```
25+
Reflection
26+
PCRE
27+
SPL
28+
MBString
29+
OpenSSL
30+
Intl
31+
ICU version
32+
Fileinfo
33+
DOM extensions
34+
GD or Imagick
35+
```
36+
37+
For more detailed check, run `php requirements.php` from the application root directory.
38+
39+
40+
## Installation
41+
42+
Before getting started make sure that you have checked the project requirements and installed [Composer](https://getcomposer.org/).
43+
44+
1. Clone or download the repo.
45+
46+
> **For security reasons, if you are using a shared hosting service it is recommended to place the project files outside from your default public_html(www) directory!**
47+
48+
2. Setup a vhost/server address (eg. `http://api.presentator.local/`) and point it to `web/`.
49+
50+
3. Run the following commands:
51+
52+
```bash
53+
# navigate to the project root dir
54+
cd /path/to/project
55+
56+
# install vendor dependencies
57+
composer install
58+
59+
# execute the init command and select the appropriate environment:
60+
# dev - for development
61+
# prod - for production
62+
# starter - this is used only for the the starter project setup (https://github.com/presentator/presentator-starter)
63+
php init
64+
```
65+
66+
4. Create a new database (with `utf8mb4_unicode_ci` or `utf8_unicode_ci` collation) and adjust the db, mailer and other component configurations in `config/base-local.php` accordingly.
67+
68+
> **All available app components with their default values could be found in `config/base.php`.**
69+
70+
5. Adjust the application parameters in `config/params-local.php.`.
71+
72+
> **All available app parameters with their default values could be found in `config/params.php`.**
73+
74+
6. Apply DB migrations.
75+
76+
```bash
77+
php /path/to/project/yii migrate
78+
```
79+
80+
7. (optional) Setup a cron task to process unread screen comments:
81+
82+
```bash
83+
# Every 30 minutes processes all unread screen comments and sends an email to the related users.
84+
*/30 * * * * php /path/to/project/yii mails/process-comments
85+
```
86+
87+
**That's it!** You should be able to make HTTP requests to the previously defined server address.
88+
89+
Additional console commands you may found useful:
90+
91+
```bash
92+
# set Super User access rights to a single User model
93+
php /path/to/project/yii users/super [email protected]
94+
95+
# set Regular User access rights to a single User model
96+
php /path/to/project/yii users/regular [email protected]
97+
```
98+
99+
100+
## Development
101+
102+
#### Running tests
103+
104+
Presentator uses [Codeception](https://codeception.com/) as its primary test framework.
105+
106+
Running tests require an additional database, which will be cleaned up between tests.
107+
Create a new database and edit the db component settings in `config/test-local.php` and then run the following console commands:
108+
109+
```bash
110+
# apply db migrations for the test database
111+
php path/to/project/yii_test migrate
112+
113+
# build the test suites
114+
/path/to/project/vendor/bin/codecept build
115+
116+
# start all application tests
117+
/path/to/project/vendor/bin/codecept run
118+
```
119+
120+
> Currently only functional tests are available.
121+
122+
#### Conventions
123+
124+
The project makes use of the following conventions:
125+
126+
- *(PHP)* Each class must follow the accepted [PSR standards](https://www.php-fig.org/psr/#accepted).
127+
- *(PHP)* Each class method should have comment block tags based on [PHPDoc](https://docs.phpdoc.org/references/phpdoc/index.html) (method description is optional).
128+
- *(DB)* Use InnoDB table engine.
129+
- *(DB)* Use `utf8mb4_unicode_ci` or `utf8_unicode_ci` collation.
130+
- *(DB)* Table names must match with the corresponding AR model class name (eg. `UserProjectRel`).
131+
- *(DB)* Table columns must be in camelCase format (eg. `passwordResetToken`)
132+
- *(DB)* Each database change must be applied via Yii migrations.
133+
- *(DB)* Whenever is possible add named foreign keys and indexes in the following format `fk_{FROM_TABLE}_to_{TO_TABLE}` and `idx_{TABLE}_{COLUMN(S)}` (eg. `fk_ProjectLink_to_Project`, `idx_ProjectLink_slug`)
134+
135+
#### DB schema
136+
137+
![erd](https://u.cubeupload.com/presentator/presentatorv2erd.png)
138+

authclients/GitLab.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
namespace presentator\api\authclients;
3+
4+
use yii\authclient\OAuth2;
5+
6+
/**
7+
* GitLab allows authentication via GitLab OAuth.
8+
*
9+
* In order to use GitLab OAuth you must register your application at <https://gitlab.com/profile/applications>.
10+
*
11+
* Example application configuration:
12+
*
13+
* ```php
14+
* 'components' => [
15+
* 'authClientCollection' => [
16+
* 'class' => \yii\authclient\Collection::class,
17+
* 'clients' => [
18+
* 'gitlab' => [
19+
* 'class' => \presentator\api\authclients\GitLab::class,
20+
* 'domain' => 'https://gitlab.com'
21+
* 'clientId' => 'gitlab_client_id',
22+
* 'clientSecret' => 'gitlab_client_secret',
23+
* ],
24+
* ],
25+
* ],
26+
* // ...
27+
* ]
28+
* ```
29+
*
30+
* @see https://docs.gitlab.com/ee/api/oauth2.html
31+
* @see https://gitlab.com/profile/applications
32+
*
33+
* @author Dmitriy Kuts <[email protected]>
34+
* @author Gani Georgiev <[email protected]>
35+
*/
36+
class GitLab extends OAuth2
37+
{
38+
/**
39+
* @var string
40+
*/
41+
public $domain = 'https://gitlab.com';
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public $authUrl = '/oauth/authorize';
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public $tokenUrl = '/oauth/token';
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public $apiBaseUrl = '/api/v4/';
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
public $scope = 'read_user';
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function init()
67+
{
68+
parent::init();
69+
70+
$this->authUrl = $this->domain . $this->authUrl;
71+
$this->tokenUrl = $this->domain . $this->tokenUrl;
72+
$this->apiBaseUrl = $this->domain . $this->apiBaseUrl;
73+
}
74+
75+
/**
76+
* {@inheritdoc}
77+
*/
78+
protected function initUserAttributes()
79+
{
80+
return $this->api('user', 'GET');
81+
}
82+
83+
/**
84+
* {@inheritdoc}
85+
*/
86+
protected function defaultName()
87+
{
88+
return 'gitlab';
89+
}
90+
91+
/**
92+
* {@inheritdoc}
93+
*/
94+
protected function defaultTitle()
95+
{
96+
return 'GitLab';
97+
}
98+
}

0 commit comments

Comments
 (0)