Added a user guide based on MkDocs

This commit is contained in:
Cédric Belin
2018-11-21 17:53:26 +01:00
parent 21d1131813
commit 4e9e67a695
11 changed files with 211 additions and 9 deletions

View File

@ -3,11 +3,14 @@
[Gitea](https://gitea.io) client library, in [PHP](https://secure.php.net).
## Resources
- [Documentation](https://github.com/sab-international/gitea.php/wiki)
- [API reference](https://sab-international.github.io/gitea.php)
## Documentation
- [User guide](https://dev.sabcomputer.com/gitea.php)
- [API reference](https://dev.sabcomputer.com/gitea.php/api)
## Development
- [Git repository](https://github.com/sab-international/gitea.php)
- [Packagist package](https://packagist.org/packages/sab-international/gitea)
- [GitHub repository](https://github.com/sab-international/gitea.php)
- [Submit an issue](https://github.com/sab-international/gitea.php/issues)
## License
[Gitea for PHP](https://github.com/sab-international/gitea.php) is distributed under the MIT License.
[Gitea for PHP](https://dev.sabcomputer.com/gitea.php) is distributed under the MIT License.

View File

@ -38,7 +38,12 @@ class RoboFile extends Tasks {
* Builds the documentation.
*/
function doc(): void {
$this->_exec('phpdoc');
$this->taskFilesystemStack()
->copy('CHANGELOG.md', 'doc/about/changelog.md')
->copy('LICENSE.md', 'doc/about/license.md')
->run();
$this->_exec('mkdocs build');
}
/**

15
doc/about/see_also.md Normal file
View File

@ -0,0 +1,15 @@
# See also
## Development
- [API reference](https://dev.sabcomputer.com/gitea.php/api)
- [Packagist package](https://packagist.org/packages/sab-international/gitea)
- [Submit an issue](https://github.com/sab-international/gitea.php/issues)
## Testing
- [Continuous integration](https://travis-ci.com/sab-international/gitea.php)
- [Code coverage](https://coveralls.io/github/sab-international/gitea.php/)
## Other implementations
- Dart: [Gitea for Dart](https://dev.belin.io/gitea.dart)
- JavaScript: [Gitea for JS](https://dev.belin.io/gitea.js)
- Yii Framework: [Gitea for Yii](https://dev.sabcomputer.com/yii2-gitea)

BIN
doc/img/gitea.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

15
doc/index.md Normal file
View File

@ -0,0 +1,15 @@
# Gitea <small>for PHP</small>
## Yet another implementation of enumerated types
This implementation, based on [traits](https://secure.php.net/manual/en/language.oop5.traits.php), does not try to reproduce the semantics of traditional enumerations, like the ones found in C# or Java languages.
Unlike other [PHP](https://secure.php.net) implementations, like the [SplEnum](https://secure.php.net/manual/en/class.splgitea.php) class, it does not rely on object instances. Instead, it just gives a set of static methods to ease working with the `public` constants of a class representing an enumerated type.
## Quick start
Install the latest version of **Enums for PHP** with [Composer](https://getcomposer.org):
```shell
composer require sab-international/gitea
```
For detailed instructions, see the [installation guide](installation.md).

39
doc/installation.md Normal file
View File

@ -0,0 +1,39 @@
# Installation
## Requirements
Before installing **Enums for PHP**, you need to make sure you have [PHP](https://secure.php.net)
and [Composer](https://getcomposer.org), the PHP package manager, up and running.
!!! warning
Enums for PHP requires PHP >= **7.2.0**.
You can verify if you're already good to go with the following commands:
```shell
php --version
# PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
composer --version
# Composer version 1.7.2 2018-08-16 16:57:12
```
!!! info
If you plan to play with the package sources, you will also need
[Robo](https://robo.li) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material).
## Installing with Composer package manager
### 1. Install it
From a command prompt, run:
```shell
composer require sab-international/gitea
```
### 2. Import it
Now in your [PHP](https://secure.php.net) code, you can use:
```php
<?php
use Enum\{EnumTrait};
```

82
doc/usage.md Normal file
View File

@ -0,0 +1,82 @@
path: src/branch/master
source: lib/EnumTrait.php
# Usage
## Create the enumeration
Just use the `Enum\EnumTrait` trait on a class:
```php
<?php
use Enum\{EnumTrait};
/**
* Specifies the day of the week.
*/
final class DayOfWeek {
use EnumTrait;
const SUNDAY = 0;
const MONDAY = 1;
const TUESDAY = 2;
const WEDNESDAY = 3;
const THURSDAY = 4;
const FRIDAY = 5;
const SATURDAY = 6;
}
```
This trait adds a private constructor to the enumerated type: it prohibits its instantiation.
Thus, the obtained enumeration can only contain static members.
You should only use [scalar constants](https://secure.php.net/manual/en/function.is-scalar.php), and possibly methods.
## Work with the enumeration
Check whether a value is defined among the enumerated type:
```php
<?php
DayOfWeek::isDefined(DayOfWeek::SUNDAY); // true
DayOfWeek::isDefined('foo'); // false
```
Ensure that a value is defined among the enumerated type:
```php
<?php
DayOfWeek::assert(DayOfWeek::MONDAY); // DayOfWeek::MONDAY
DayOfWeek::assert('foo'); // (throws \UnexpectedValueException)
DayOfWeek::coerce(DayOfWeek::MONDAY); // DayOfWeek::MONDAY
DayOfWeek::coerce('bar'); // null
DayOfWeek::coerce('baz', DayOfWeek::TUESDAY); // DayOfWeek::TUESDAY
```
Get the zero-based position of a value in the enumerated type declaration:
```php
<?php
DayOfWeek::getIndex(DayOfWeek::WEDNESDAY); // 3
DayOfWeek::getIndex('foo'); // -1
```
Get the name associated to an enumerated value:
```php
<?php
DayOfWeek::getName(DayOfWeek::THURSDAY); // "THURSDAY"
DayOfWeek::getName('foo'); // "" (empty)
```
Get information about the enumerated type:
```php
<?php
DayOfWeek::getEntries();
// ["SUNDAY" => 0, "MONDAY" => 1, "TUESDAY" => 2, "WEDNESDAY" => 3, "THURSDAY" => 4, "FRIDAY" => 5, "SATURDAY" => 6]
DayOfWeek::getNames();
// ["SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"]
DayOfWeek::getValues();
// [0, 1, 2, 3, 4, 5, 6]
```

View File

@ -244,7 +244,7 @@ class Repository implements \JsonSerializable {
*/
function getName(): string {
if (mb_strlen($this->name)) return $this->name;
return mb_strlen($fullName = $this->getFullName()) ? explode('/', $fullName, 2)[0] : '';
return mb_strlen($fullName = $this->getFullName()) ? explode('/', $fullName)[1] : '';
}
/**

View File

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace Gitea\Models;
/**
* Warps the version of the Gitea server.
* Wraps the version of the Gitea server.
*/
class ServerVersion implements \JsonSerializable {

View File

@ -21,7 +21,7 @@ final class StatusState {
const FAILURE = 'failure';
/**
* @var string The status is a pending.
* @var string The status is pending.
*/
const PENDING = 'pending';

43
mkdocs.yml Normal file
View File

@ -0,0 +1,43 @@
site_name: SAB Rich Text Editor
site_description: A customized build of CKEditor, a rich text editor.
site_author: SAB International - contact@sabcomputer.com
site_url: https://dev.sabcomputer.com/gitea.php
docs_dir: doc
site_dir: web
repo_name: GitHub
repo_url: https://github.com/sab-international/gitea.php
edit_uri: edit/master/doc/
copyright: Copyright &copy; 2018 SAB International
google_analytics:
- !!python/object/apply:os.getenv [GOOGLE_ANALYTICS_ID]
- auto
extra:
social:
- {type: globe, link: 'http://www.sabcomputer.com'}
- {type: github, link: 'https://github.com/sab-international'}
- {type: facebook, link: 'https://www.facebook.com/sabinternational34'}
- {type: twitter, link: 'https://twitter.com/SABDistribution'}
- {type: linkedin, link: 'https://linkedin.com/company/sab-international-sarl'}
markdown_extensions:
- admonition
- codehilite
- meta
nav:
- Overview: index.md
- Installation: installation.md
- Usage: usage.md
- About:
- Changelog: about/changelog.md
- License: about/license.md
- See also: about/see_also.md
theme:
name: material
favicon: img/favicon.ico
palette: {primary: deep purple, accent: deep purple}