|
| 1 | +Presentator v2 REST API [](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 | + |
| 138 | + |
0 commit comments