mirror of
				https://github.com/sitelease/sugar-cube-client.git
				synced 2025-10-31 12:02:30 +01:00 
			
		
		
		
	Added a user guide based on MkDocs
This commit is contained in:
		
							
								
								
									
										15
									
								
								doc/about/see_also.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								doc/about/see_also.md
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										
											BIN
										
									
								
								doc/img/gitea.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 13 KiB | 
							
								
								
									
										15
									
								
								doc/index.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								doc/index.md
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										39
									
								
								doc/installation.md
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										82
									
								
								doc/usage.md
									
									
									
									
									
										Normal 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] | ||||
| ``` | ||||
		Reference in New Issue
	
	Block a user