### Gini CLI Commands for Project Setup and Preview Source: https://github.com/iamfat/gini-book/blob/master/cgi/write_hello_world.md A set of bash commands used to initialize a Gini project, update dependencies, clear cache, update web assets, and start a development server for previewing the application. ```bash gini composer init -f composer update gini cache gini web update ``` ```bash # 开始运行 gini web preview # default is localhost:3000 ``` -------------------------------- ### Run Gini Development Environment with Docker Source: https://github.com/iamfat/gini-book/blob/master/get_started/installation.md Pulls the pre-configured Gini development Docker image and runs it as a container, exposing port 9000. This provides a ready-to-use Gini environment without manual setup. ```docker docker pull genee/gini-dev docker run --name gini-dev -d -p 9000:9000 genee/gini-dev ``` -------------------------------- ### Download Gini via Git Source: https://github.com/iamfat/gini-book/blob/master/get_started/installation.md Clones the Gini repository into the user's home directory to set up the Gini modules. This is the primary method for obtaining the Gini framework files. ```bash mkdir $HOME/gini-modules cd $HOME/gini-modules git clone https://github.com/iamfat/gini.git ``` -------------------------------- ### Run Gini Test Server Source: https://github.com/iamfat/gini-book/blob/master/api/write_an_api.md Commands to set up and run a local test server for the Gini application. These commands prepare the environment and start the preview server. ```bash $ gini cache $ gini config update $ gini web update $ gini web preview # default is localhost:3000 ``` -------------------------------- ### Gini Framework CLI Commands Source: https://github.com/iamfat/gini-book/blob/master/cli/write_hello,_world.md A sequence of bash commands to set up the Gini project, install dependencies, clear the cache, and execute the custom 'hello world' CLI command. ```bash gini composer init -f composer update gini install gini cache gini hello world ``` -------------------------------- ### Configure Gini for Global Environment Source: https://github.com/iamfat/gini-book/blob/master/get_started/installation.md Installs Gini to a system-wide location and updates the global PATH environment variable via /etc/profile.d/gini.sh. This makes Gini accessible to all users on the system. ```bash mkdir -p /usr/local/share/gini-modules git clone https://github.com/iamfat/gini /usr/local/share/gini-modules/gini # Add the following to /etc/profile.d/gini.sh export PATH=/usr/local/share/gini/bin:$PATH ``` -------------------------------- ### Gini Module Entry Point Example Source: https://github.com/iamfat/gini-book/blob/master/cgi/request_lifecycle.md Demonstrates the structure of a Gini module's entry point class, including `setup` and `shutdown` methods. These methods are called during the request lifecycle for module initialization and cleanup. ```php namespace Gini\Module; class MyModule extends Prototype { public static function setup() { // run when each request started } public static function shutdown() { // run when each request finished } } ``` -------------------------------- ### Install a Gini Module Source: https://github.com/iamfat/gini-book/blob/master/deployment/gini_index.md Installs a specified Gini module from the index. It fetches the index file and downloads the module package, then extracts it to the target directory. ```bash $ gini install my-module '*' Fetching INDEX file for my-module... Downloading my-module from my-module/1.2.0.tgz... Extracting my-module to /path/to/my-module... ``` -------------------------------- ### Configure Gini for User Environment Source: https://github.com/iamfat/gini-book/blob/master/get_started/installation.md Adds the Gini binary directory to the user's PATH environment variable in ~/.profile. This allows the Gini command-line tools to be accessed from any terminal session for the current user. ```bash export PATH=$HOME/gini-modules/gini/bin:$PATH ``` -------------------------------- ### Gini Controller for Hello World Source: https://github.com/iamfat/gini-book/blob/master/cgi/write_hello_world.md Defines a Gini controller class `Hello` with an `actionWorld` method that renders an HTML view. It sets up the necessary namespace and extends the base Gini CGI controller. ```php 'world']); return new \Gini\CGI\Response\HTML($view); } } ``` -------------------------------- ### PHP CLI Controller for 'Hello, world!' Source: https://github.com/iamfat/gini-book/blob/master/cli/write_hello,_world.md Defines a CLI controller class 'Hello' with an 'actionWorld' method that outputs 'Hello, world!'. This is the core logic for the CLI command. ```php whose('name')->beginWith('J') ->andWhose('father')->isIn( those('users')->whose('email')->contains('genee') ); ``` -------------------------------- ### Gini View Template for Hello World Source: https://github.com/iamfat/gini-book/blob/master/cgi/write_hello_world.md An HTML view template (`hello.phtml`) that displays a greeting. It uses PHP's short echo tag to output a variable passed from the controller. ```html

Hello, !

``` -------------------------------- ### Those ORM - Natural Language Query Example Source: https://github.com/iamfat/gini-book/blob/master/overview/about_gini.md An example showcasing the Those ORM's natural language-like syntax for querying database records. This snippet demonstrates how to find users whose names start with 'J' and whose fathers' emails contain 'genee'. ```php // 查询所有名字以'J'开头, 爸爸的email中存在genee的用户 $users = those('users') ->whose('name')->beginWith('J') ->andWhose('father')->isIn( those('users')->whose('email')->contains('genee') ); ``` -------------------------------- ### Gini CLI Command Routing Example Source: https://github.com/iamfat/gini-book/blob/master/cli/concept.md Illustrates how Gini maps command-line interface (CLI) commands to specific controller actions. Shows different routing possibilities for a 'gini hello world' command. ```shell gini hello world => \Gini\Controller\CLI\Hello::actionWorld() \Gini\Controller\CLI\Hello::__index($world) \Gini\Controller\CLI\Index::actionHello($world) \Gini\Controller\CLI\Index::__index($hello, $world) ``` -------------------------------- ### Call Gini API from PHP Source: https://github.com/iamfat/gini-book/blob/master/api/write_an_api.md Demonstrates how to use the Gini RPC client to call the previously defined 'hello->world' API endpoint and display the response. It requires the RPC client to be initialized with the API's base URL. ```php hello->world(); echo $response; // "Hello, world!"; ``` -------------------------------- ### PHPUnit Test Case Example Source: https://github.com/iamfat/gini-book/blob/master/testing/phpunit.md An example of a basic PHPUnit test case class extending `Gini\PHPUnit\TestCase\CLI`, demonstrating a simple test method. ```php assertTrue(false, "PLEASE IMPLEMENT THIS!"); } } ``` -------------------------------- ### Update Composer Packages for Gini App Source: https://github.com/iamfat/gini-book/blob/master/deployment/gini_composer_mirror.md Initializes Composer configuration for Gini modules and installs the packages. This process ensures that the necessary dependencies for Gini applications are set up correctly. ```bash $ gini composer init Generating Composer configuration file... done. $ composer install ``` -------------------------------- ### Global Router Configuration Source: https://github.com/iamfat/gini-book/blob/master/cgi/routing.md Shows how to access and configure the global router instance using `\Gini\CGI::router()` and its HTTP method helpers (get, post, put, delete, etc.). ```php $router = \Gini\CGI::router(); $router and $router->get('hello/world', 'Hello@actionWorld'); ``` -------------------------------- ### 从Gini模块调用REST API Source: https://github.com/iamfat/gini-book/blob/master/rest/write_an_api.md 通过实例化`Gini\REST`类并提供RESTful服务的URL,可以方便地调用远程API。示例展示了如何使用`get`方法获取文章,以及使用`post`方法提交文章数据。 ```php get('hello/article/1'); echo $response; // "Hello, world!"; $response = $rest->post('hello/article', ['author'=>'libai', 'title'=>'jiangjinjiu', 'body'=>'balabala']); ``` -------------------------------- ### Gini Module Class Structure Source: https://github.com/iamfat/gini-book/blob/master/cli/concept.md Defines the standard structure for a Gini module class, including static methods for setup, shutdown, and diagnostics. These methods are called during the application lifecycle. ```php namespace Gini\Module; class MyModule { static function setup() { // run when each request started } static function shutdown() { // run when each request finished } static function diagnose() { // run to check all things required for module // will be called by `gini doctor` } } ``` -------------------------------- ### Define CGI Request Routes Source: https://github.com/iamfat/gini-book/blob/master/cgi/routing.md Defines how to set up request routes for a module, mapping URL paths to specific Controller actions using HTTP methods like GET, PUT. ```php namespace Gini\Module; class Hello { public static function cgiRoute($router) { $router->get('hello/world', 'Real\Hello@actionWorld'); $router ->get('user/{id}', 'REST\Hello@getUser') ->put('user/{id}/comment/{comment}', 'REST\Hello@postComment'); } } ``` -------------------------------- ### 初始化Gini应用 Source: https://github.com/iamfat/gini-book/blob/master/get_started/write_first_app.md 使用`gini init`命令创建一个新的Gini应用项目。该命令会引导用户输入应用的基本信息,并在项目根目录生成`gini.json`配置文件。 ```bash $ mkdir sample $ cd sample $ gini init Shortname [sample]: Name [Sample]: Description [App description...]: Version [0.1]: Dependencies [N/A]: $ _ ``` -------------------------------- ### Gini CLI Usage Source: https://github.com/iamfat/gini-book/blob/master/overview/about_gini.md Demonstrates the basic usage of the Gini command-line interface (CLI) for creating and invoking applications, similar to Composer or npm. ```php gini foo bar ``` -------------------------------- ### Initialize PHPUnit Environment Source: https://github.com/iamfat/gini-book/blob/master/testing/phpunit.md Initializes the PHPUnit environment by creating the `ci/test` directory and the `phpunit.xml.dist` configuration file. ```bash gini ci phpunit init # 这会生成ci/test目录和phpunit.xml.dist ``` -------------------------------- ### Gini应用配置文件 Source: https://github.com/iamfat/gini-book/blob/master/get_started/write_first_app.md 展示了`gini init`命令生成的`gini.json`文件的结构和内容。该文件包含了应用的ID、名称、描述、版本和依赖信息。 ```json { "id": "sample", "name": "Sample", "description": "App description...", "version": "0.1", "dependencies": "" } ``` -------------------------------- ### Gini RPC Client Initialization and Method Call Source: https://github.com/iamfat/gini-book/blob/master/api/json-rpc_20_over_http.md Demonstrates how to initialize the Gini RPC client and make a remote procedure call. It shows the basic structure for sending requests and receiving results. ```php $rpc = new \Gini\RPC('http://path/to/api'); $ret = $rpc->hello->world(1, "abc"); ``` -------------------------------- ### 运行Gini测试服务器 Source: https://github.com/iamfat/gini-book/blob/master/rest/write_an_api.md 使用Gini命令行工具来更新Web应用并启动预览服务器。首先运行`gini cache`来清除缓存,然后运行`gini web update`来更新Web应用。最后,使用`gini web preview `启动预览服务器,默认地址为`localhost:3000`。 ```bash $ gini cache $ gini web update $ gini web preview # default is localhost:3000 ``` -------------------------------- ### Applying Environment-Specific Configuration (Bash) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Demonstrates how to activate environment-specific configurations. This is done by setting the `GINI_ENV` environment variable or passing the environment name as a parameter to the `gini config update` command. ```bash GINI_ENV=development gini config update gini cache ``` -------------------------------- ### Environment-Specific Configuration (YAML) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Shows how to define environment-specific configurations by creating directories prefixed with '@' (e.g., `@development`) within the `raw/config` directory. This allows for different settings across various deployment environments. ```yaml default: dsn: mysql:dbname=test;host=localhost username: genee ``` -------------------------------- ### Environment Variable Substitution in Configuration (YAML) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Explains how to use environment variables within configuration files using the `${PLACEHOLDER}` syntax. These placeholders are resolved by setting variables in a top-level `.env` file. ```yaml default: dsn: mysql:dbname=${DBNAME};host=${DBHOST} username: ${DBUSER} ``` -------------------------------- ### Setting Configuration Values (PHP) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Illustrates how to programmatically set configuration values during runtime using the `Gini\Config::set()` method. This allows for dynamic modification of application settings. ```php \Gini\Config::set('system.timezone', 'Asia/Shanghai'); ``` -------------------------------- ### Accessing Configuration Values (PHP) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Demonstrates how to retrieve configuration values at runtime using the `Gini\Config::get()` method. This is essential for dynamically applying settings within your application. ```php $timezone = \Gini\Config::get('system.timezone'); ``` -------------------------------- ### Configure Composer Mirror for China Source: https://github.com/iamfat/gini-book/blob/master/deployment/gini_composer_mirror.md Sets up a Composer mirror to `packagist.phpcomposer.com` to address slow download speeds from Packagist.org in China. This global configuration improves package retrieval performance. ```bash $ composer config -g repo.packagist composer https://packagist.phpcomposer.com ``` -------------------------------- ### Configuration Command-Line Interface (Bash) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Provides essential command-line operations for managing Gini framework configurations. This includes updating the configuration cache, exporting configurations, and exporting in JSON format. ```bash # Generate configuration cache to ensure configurations are effective gini cache # Output configuration gini config export gini config export --json ``` -------------------------------- ### Defining Environment Variables in .env File (Bash) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Shows how to define environment variables in the `.env` file located at `APP_PATH/.env`. These variables are then used to substitute placeholders in the configuration files. ```bash DBNAME=test DBHOST=localhost DBUSER=genee ``` -------------------------------- ### Manage Gini Module Authentication and Publishing Source: https://github.com/iamfat/gini-book/blob/master/deployment/gini_index.md Handles login, logout, and checking the current user for Gini module operations. Allows publishing and unpublishing without repeated password prompts after initial login. ```bash # Login $ gini index login doejohn Password: You've successfully logged in as doejohn! # Check current user $ gini index who Hey! You are doejohn. # Publish module $ gini index publish 1.2.0 my-module/1.2.0 was published successfully. # Unpublish module $ gini index unpublish 1.2.0 my-module/1.2.0 was unpublished successfully. # Logout $ gini index logout You are logged out now. # Check current user after logout $ gini index who Oops. You are NOBODY. ``` -------------------------------- ### Create PHPUnit Test File Source: https://github.com/iamfat/gini-book/blob/master/testing/phpunit.md Creates a new PHPUnit test file for a specified test case, generating the file in the `ci/test` directory. ```bash gini ci phpunit create Hello/World # 这会生成 ci/test/Hello/World.php 文件 ``` -------------------------------- ### 创建REST API控制器 Source: https://github.com/iamfat/gini-book/blob/master/rest/write_an_api.md 定义一个继承自`Gini\Controller\REST`的类,实现HTTP方法(如`getArticle`, `postArticle`)来处理API请求。`getArticle`方法返回一个JSON响应,`postArticle`方法接收作者、标题和正文作为参数并返回JSON响应。 ```php "world"]); } public function postArticle($author, $title, $body) { // return \Gini\CGI\Response\JSON(["message"=>"A.O."], 401); return \Gini\CGI\Response\JSON(["hello"=>"world"]); } } } ``` -------------------------------- ### Default Values for Environment Variables (YAML) Source: https://github.com/iamfat/gini-book/blob/master/get_started/configuration.md Illustrates how to provide default values for environment variables within configuration files, similar to bash's default variable settings. This prevents system errors if a variable is not defined. ```yaml default: dsn: mysql:dbname=${DBNAME:="abc"};host=${DBHOST:="127.0.0.1"} ``` -------------------------------- ### Named Variable Adaptation in Routing Source: https://github.com/iamfat/gini-book/blob/master/cgi/routing.md Explains how named variables in routes (e.g., `{var}`) are automatically mapped to Controller action parameters by reflection, regardless of parameter order. ```php $router->get('user/{uid}/comment/{comment}', 'REST\Hello@postComment'); class Hello extends REST { public function postComment($comment, $uid) { // Parameters are automatically assigned based on variable names. } } ``` -------------------------------- ### Check Gini Version Source: https://github.com/iamfat/gini-book/blob/master/deployment/gini_index.md Displays the current Gini module version or sets a new version. This command is used to query and manage the version information of Gini modules. ```bash $ gini version my-module/1.2.0 $ gini version 1.3.0-beta my-module/1.3.0-beta ``` -------------------------------- ### Publish/Unpublish Gini Modules Source: https://github.com/iamfat/gini-book/blob/master/deployment/gini_index.md Publishes or unpublishes a Gini module to the index. Requires a Git tag for the version. The process uses `git-archive` to prepare the package. ```bash # Tag the commit $ cd /path/to/my-module $ git tag 1.2.0 # Publish module $ gini index publish 1.2.0 User: doejohn Password: my-module/1.2.0 was published successfully. # Unpublish module $ gini index unpublish 1.2.0 User: doejohn Password: my-module/1.2.0 was unpublished successfully. ``` -------------------------------- ### Gini CGI Controller Routing Source: https://github.com/iamfat/gini-book/blob/master/cgi/request_lifecycle.md Illustrates how Gini maps URL paths to specific CGI controller actions based on PHP's autoloading conventions. This allows for direct mapping of requests to controller methods. ```APIDOC URL Path Mapping: /hello/world => \Gini\Controller\CGI\Hello::actionWorld() \Gini\Controller\CGI\Hello::__index($world) \Gini\Controller\CGI\Index::actionHello($world) \Gini\Controller\CGI\Index::__index($hello, $world) ``` -------------------------------- ### Gini CGI Router API Source: https://github.com/iamfat/gini-book/blob/master/cgi/routing.md Provides an overview of the Gini CGI Router API for defining web request routes. It covers methods for mapping URLs to controller actions and handling dynamic parameters. ```APIDOC Gini\CGI::router() - Returns the global router instance. Router::get(path, action) - Registers a GET request route. - path: The URL path, can include named parameters like {param}. - action: The controller action to execute, e.g., 'ControllerName@methodName'. Router::post(path, action) - Registers a POST request route. Router::put(path, action) - Registers a PUT request route. Router::delete(path, action) - Registers a DELETE request route. Router::options(path, action) - Registers an OPTIONS request route. Router::any(path, action) - Registers a route that matches any HTTP method. Router::get(path, callback) - Registers a GET request route with a closure callback. Nested Routing: - Routes can be nested by passing a callback to router methods, which receives the router instance. Named Variable Adaptation: - Parameters in the path defined as {variable_name} are automatically passed to the controller action method if the method has parameters with matching names. - Example: Route 'user/{uid}/comment/{comment}' maps to a method `postComment($comment, $uid)`. ``` -------------------------------- ### JSON-RPC 2.0 Request Format Source: https://github.com/iamfat/gini-book/blob/master/api/json-rpc_20_over_http.md Illustrates the standard JSON-RPC 2.0 request payload structure, including version, method, parameters, and ID. ```json {"jsonrpc": "2.0", "method": "hello/world", "params": [1, "abc"], "id": 1} ``` -------------------------------- ### Handling RPC Errors with Gini Exceptions Source: https://github.com/iamfat/gini-book/blob/master/api/json-rpc_20_over_http.md Demonstrates the error handling mechanism using a try-catch block to capture `\Gini\RPC\Exception` when a remote procedure call fails. ```php try { $rpc = new \Gini\RPC('http://path/to/api'); $ret = $rpc->hello->world(1, "abc"); } catch (\Gini\RPC\Exception $e) { // catch the exception } ``` -------------------------------- ### Nested Request Routing Source: https://github.com/iamfat/gini-book/blob/master/cgi/routing.md Demonstrates how request routes can be nested, allowing for hierarchical route definitions within a callback function. ```php $router->get('nested/to', function($router) { $router->get('some-place/action', 'Real\Place@someAction'); }); ``` -------------------------------- ### Retrieving RPC Call Result Source: https://github.com/iamfat/gini-book/blob/master/api/json-rpc_20_over_http.md Explains how to access the result returned from a successful RPC call in PHP, where the return value directly holds the result data. ```php $rpc = new \Gini\RPC('http://path/to/api'); $ret = $rpc->hello->world(1, "abc"); // $ret = 'Hello, world!' ``` -------------------------------- ### JSON-RPC 2.0 Success Response Format Source: https://github.com/iamfat/gini-book/blob/master/api/json-rpc_20_over_http.md Shows the expected JSON-RPC 2.0 response format for a successful remote procedure call, containing the result and the original request ID. ```json {"jsonrpc": "2.0", "result": "Hello, world!", "id": 1} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.