mirror of
				https://github.com/sitelease/sugar-cube-client.git
				synced 2025-10-31 12:02:30 +01:00 
			
		
		
		
	Updated the documentation
This commit is contained in:
		| @ -1,12 +1,10 @@ | |||||||
| # Gitea <small>for PHP</small> | # Gitea <small>for PHP</small> | ||||||
|  |  | ||||||
|  |  | ||||||
| ## Yet another implementation of enumerated types | [Gitea](https://gitea.io) client library, in [PHP](https://secure.php.net). | ||||||
| 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 | ## Quick start | ||||||
| Install the latest version of **Enums for PHP** with [Composer](https://getcomposer.org): | Install the latest version of **Gitea for PHP** with [Composer](https://getcomposer.org): | ||||||
|  |  | ||||||
| ```shell | ```shell | ||||||
| composer require sab-international/gitea | composer require sab-international/gitea | ||||||
|  | |||||||
| @ -1,20 +1,20 @@ | |||||||
| # Installation | # Installation | ||||||
|  |  | ||||||
| ## Requirements | ## Requirements | ||||||
| Before installing **Enums for PHP**, you need to make sure you have [PHP](https://secure.php.net) | Before installing **Gitea 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. | and [Composer](https://getcomposer.org), the PHP package manager, up and running. | ||||||
|  |  | ||||||
| !!! warning | !!! warning | ||||||
|     Enums for PHP requires PHP >= **7.2.0**. |     Gitea for PHP requires PHP >= **7.2.0**. | ||||||
|      |      | ||||||
| You can verify if you're already good to go with the following commands: | You can verify if you're already good to go with the following commands: | ||||||
|  |  | ||||||
| ```shell | ```shell | ||||||
| php --version | php --version | ||||||
| # PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS ) | # PHP 7.2.10-0ubuntu1 (cli) (built: Sep 13 2018 13:38:55) ( NTS ) | ||||||
|  |  | ||||||
| composer --version | composer --version | ||||||
| # Composer version 1.7.2 2018-08-16 16:57:12 | # Composer version 1.7.3 2018-11-01 10:05:06 | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| !!! info | !!! info | ||||||
| @ -35,5 +35,5 @@ Now in your [PHP](https://secure.php.net) code, you can use: | |||||||
|  |  | ||||||
| ```php | ```php | ||||||
| <?php | <?php | ||||||
| use Enum\{EnumTrait}; | use Gitea\{Repository, Team, User}; | ||||||
| ``` | ``` | ||||||
|  | |||||||
							
								
								
									
										82
									
								
								doc/usage.md
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								doc/usage.md
									
									
									
									
									
								
							| @ -1,82 +1,2 @@ | |||||||
| path: src/branch/master |  | ||||||
| source: lib/EnumTrait.php |  | ||||||
| # Usage | # Usage | ||||||
|  | TODO: document the usage of the **Gitea for PHP** library. | ||||||
| ## 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] |  | ||||||
| ``` |  | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| site_name: SAB Rich Text Editor | site_name: SAB Rich Text Editor | ||||||
| site_description: A customized build of CKEditor, a rich text editor. | site_description: Gitea client library, in PHP. | ||||||
| site_author: SAB International - contact@sabcomputer.com | site_author: SAB International - contact@sabcomputer.com | ||||||
| site_url: https://dev.sabcomputer.com/gitea.php | site_url: https://dev.sabcomputer.com/gitea.php | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user