### Install Webman Framework Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/plugin/console.md Executes the Webman framework installation script for initial project setup. This command is used for project initialization. ```bash php webman install ``` -------------------------------- ### Configure Global and Application Middleware Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/middleware.md Example configuration for `config/middleware.php` showing how to register both global middleware and application-specific middleware in a multi-application setup. ```php return [ // Global middleware '' => [ app\middleware\AuthCheckTest::class, app\middleware\AccessControlTest::class, ], // API application middleware (application middleware only takes effect in multi-application mode) 'api' => [ app\middleware\ApiOnly::class, ] ]; ``` -------------------------------- ### Basic Redis Usage Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/redis.md Demonstrates setting and getting a value from Redis using the static Redis facade. This example assumes a default Redis connection is configured. ```php ``` ```bash php webman app-plugin:install foo ``` -------------------------------- ### Start Webman Server Source: https://github.com/webman-php/webman-manual/blob/master/README.md Use this command to start the webman server. ```bash php server/start.php start ``` -------------------------------- ### Install and Run Unit Tests Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/validation.md Instructions to install dependencies and run unit tests from the webman/validation root directory. ```bash composer install vendor\bin\phpunit -c phpunit.xml ``` -------------------------------- ### Install PHPUnit Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/unitest.md Install the PHPUnit testing framework using Composer. ```bash composer require --dev phpunit/phpunit ``` -------------------------------- ### Install php-di Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/di.md Install the php-di library using composer. This is the first step to enable dependency injection. ```bash composer require php-di/php-di:^7.0 ``` -------------------------------- ### Install Webman Database Component Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/tutorial.md Install the webman/database component along with pagination, events, and var-dumper. A server restart is required after installation. ```bash composer require -W webman/database illuminate/pagination illuminate/events symfony/var-dumper ``` -------------------------------- ### Think-Cache API Examples Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/thinkcache.md Provides examples of common cache operations using the Cache facade. This includes setting, checking existence, getting, deleting, clearing, pulling, and remembering cache entries. ```php // Set cache Cache::set('val','value',600); // Check if cache exists Cache::has('val'); // Get cache Cache::get('val'); // Delete cache Cache::delete('val'); // Clear cache Cache::clear(); // Read and delete cache Cache::pull('val'); // Write if not exists Cache::remember('val',10); ``` -------------------------------- ### Install Payment SDK Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/pay.md Install the Payment SDK using Composer. Use the -vvv flag for verbose output. ```php composer require yansongda/pay -vvv ``` -------------------------------- ### Basic Session Interaction Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/session.md Demonstrates how to get the session instance from a request, set a session variable, and retrieve it to display a greeting. Session data is automatically saved when the session object is destroyed. ```php get('name'); $session = $request->session(); $session->set('name', $name); return response('hello ' . $session->get('name')); } } ``` -------------------------------- ### Closure Route Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/route.md Define a route that executes a closure function. The route path must start with a '/'. Accessing this route will return the response from the closure. ```php use support\Request; Route::any('/test', function (Request $request) { return response('test'); }); ``` -------------------------------- ### Start Standalone Binary Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/plugin/console.md Starts the application packaged as a standalone binary. A runtime directory will be created for log files. Custom INI settings can be applied via 'custom_ini' in config/plugin/webman/console/app.php. ```bash ./webman.bin start ``` -------------------------------- ### Install PHP and Composer on Linux/macOS Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/install.md Use this command to install PHP and Composer on Linux and macOS systems. Windows users need to install PHP separately. ```bash curl -sO https://www.workerman.net/install-php-and-composer && sudo bash install-php-and-composer ``` -------------------------------- ### Install Webman Database Component (Minimal) Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/tutorial.md Install only the webman/database component if pagination, database events, or SQL logging are not needed. ```bash composer require -W webman/database ``` -------------------------------- ### Install Application Plugin from Source Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/app/install.md Use this command to install an application plugin after downloading and extracting its source package to the plugin directory. ```bash php webman app-plugin:install plugin-name ``` -------------------------------- ### Start Webman Phar Application Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/others/phar.md Start the webman application packaged as a Phar file. The -d option can be used to start it in daemon mode. ```bash php webman.phar start ``` ```bash php webman.phar start -d ``` -------------------------------- ### Install Paginator Component Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/paginator.md Install the jasongrimes/paginator component using Composer. ```bash composer require "jasongrimes/paginator:^1.0.3" ``` -------------------------------- ### Full Custom Process Configuration Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/process.md A comprehensive example of a custom process configuration in `config/process.php`, detailing all available options such as handler, listen, count, user, group, reloadable, reusePort, transport, context, constructor, and enable. ```php return [ // ... // websocket_test is the process name 'websocket_test' => [ // Specify the process class here 'handler' => app\Pusher::class, // Protocol, IP and port to listen on (optional) 'listen' => 'websocket://0.0.0.0:8888', // Number of processes (optional, default is 1) 'count' => 2, // User to run the process (optional, default is the current user) 'user' => '', // User group to run the process (optional, default is the current user group) 'group' => '', // Whether the current process supports reload (optional, default is true) 'reloadable' => true, // Whether to enable reusePort 'reusePort' => true, // Transport (optional, set to 'ssl' when SSL is required, default is 'tcp') 'transport' => 'tcp', // Context (optional, pass certificate path when transport is 'ssl') 'context' => [], // Constructor parameters for the process class (optional) 'constructor' => [], // Whether this process is enabled 'enable' => true ], ]; ``` -------------------------------- ### Install Response Code Message Component Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/generate_error_code.md Install the necessary component using Composer. ```bash composer require teamones/response-code-msg ``` -------------------------------- ### Install MongoDB Package Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/mongo.md Install the webman database and mongodb/laravel-mongodb packages using composer. A server restart is required after installation. ```bash composer require -W webman/database mongodb/laravel-mongodb ^4.8 ``` -------------------------------- ### Install Webman Push Plugin Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/plugin/push.md Install the webman/push plugin using composer. ```sh composer require webman/push ``` -------------------------------- ### Install a Webman Plugin Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/plugin/console.md Installs a plugin by its package name. Use either the argument or the --name option to specify the plugin. ```bash php webman plugin:install ``` ```bash php webman plugin:install --name ``` ```bash php webman plugin:install foo/my-admin ``` ```bash php webman plugin:install --name foo/my-admin ``` -------------------------------- ### Upgrade Webman and Install Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/upgrade/1-5.md Execute these composer commands to upgrade to Webman framework 1.5 and install the console component. ```bash composer require workerman/webman-framework ^1.5 -W && composer require webman/console ^1.2.12 && php webman install ``` -------------------------------- ### Install webman/stomp Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/queue/stomp.md Install the webman/stomp plugin using composer. ```bash composer require webman\/stomp ``` -------------------------------- ### Start Static PHP with Custom php.ini Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/others/bin.md Use this command to start a standalone static PHP executable, specifying a custom php.ini file. ```bash php -c /your/path/php.ini start.php start -d ``` -------------------------------- ### Install Webman Event Library Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/event.md Install the webman-event package using composer. ```shell composer require tinywan/webman-event ``` -------------------------------- ### Configure Process to Start with Webman Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/crontab.md Add the task process configuration to config/process.php to ensure it starts with the webman application. ```php return [ ....other config omitted.... 'task' => [ 'handler' => app\process\Task::class ], ]; ``` -------------------------------- ### Install Captcha Component Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/captcha.md Install the Captcha component using Composer. ```bash composer require webman/captcha ``` -------------------------------- ### Install Translation Component Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/translation.md Install the symfony/translation component using Composer. ```bash composer require symfony/translation ``` -------------------------------- ### Start webman services with Docker Compose Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/install.md Attach to the console to start all services when using Docker Compose. ```bash docker-compose up ``` -------------------------------- ### Install Webman Rate Limiter Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/rate-limiter.md Install the webman/limiter package using Composer. ```bash composer require webman/limiter ``` -------------------------------- ### Start Packaged Webman Application Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/others/bin.md Upload the generated webman.bin to a Linux server and run it to start the application. The -d flag runs it in detached mode. ```bash ./webman.bin start ``` ```bash ./webman.bin start -d ``` -------------------------------- ### Start PHAR Archive Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/plugin/console.md Starts the application packaged as a PHAR archive. A runtime directory will be created for logs and temporary files. If using .env, place it alongside the PHAR file. ```bash php webman.phar start ``` -------------------------------- ### Install Phinx using Composer Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/migration.md Install the Phinx library using Composer. This command should be run in your project's root directory. ```bash composer require robmorgan/phinx ``` -------------------------------- ### Install Proxy Manager LTS Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/di.md Install the necessary package for lazy loading with proxy management. ```bash composer require friendsofphp/proxy-manager-lts ``` -------------------------------- ### Install Webman Cache Component Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/cache.md Install the webman/cache component using Composer. ```php composer require -W webman/cache ``` -------------------------------- ### Install Payment SDK Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/payment.md Install the Payment SDK using Composer. Ensure you are using version 3.0.0 or higher. ```php composer require yansongda/pay ^3.0.0 ``` -------------------------------- ### ab Stress Test Command Examples Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/others/benchmarks.md Examples of using the 'ab' (ApacheBench) tool for stress testing, showing how to configure the number of requests, concurrency, and whether to enable keep-alive. ```bash # 100000 requests, 200 concurrency, enable keep-alive ab -n100000 -c200 -k http://127.0.0.1:8787/ ``` ```bash # 100000 requests, 200 concurrency, disable keep-alive ab -n100000 -c200 http://127.0.0.1:8787/ ``` -------------------------------- ### Install webman-permission Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/casbin.md Install the webman-permission extension using Composer. Requires PHP 7.1+ and ThinkORM. ```bash composer require tinywan/webman-permission ``` -------------------------------- ### Install Casbin Package Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/casbin.md Install the Casbin Composer package using the command below. This is the initial step for integrating Casbin into your project. ```php composer require teamones/casbin ``` -------------------------------- ### Install webman Console Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/app/create.md Install the webman command line tool using composer. This is a prerequisite for creating plugins. ```bash composer require webman/console ``` -------------------------------- ### Install PhpSpreadsheet Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/excel.md Install the PhpSpreadsheet library using Composer. This is the first step to enable Excel functionality. ```php composer require phpoffice/phpspreadsheet ``` -------------------------------- ### Generate Bootstrap Class Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/plugin/console.md Use this command to generate a bootstrap initialization class. The `start` method is called automatically on process start for global initialization. Options include plugin generation, custom paths, and overwriting. ```bash php webman make:bootstrap ``` ```bash # Create MyBootstrap in app/bootstrap php webman make:bootstrap MyBootstrap ``` ```bash # Create without auto-enabling php webman make:bootstrap MyBootstrap no ``` ```bash # Create in plugin php webman make:bootstrap MyBootstrap -p admin ``` ```bash # Custom path php webman make:bootstrap MyBootstrap -P plugin/admin/app/bootstrap ``` ```bash # Overwrite existing file php webman make:bootstrap MyBootstrap -f ``` -------------------------------- ### Complete Validator Generation Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/validation.md A comprehensive command example demonstrating the generation of a validator class with table-based rules, specific database connection, CRUD scenes, ORM selection, and force overwrite. ```bash php webman make:validator UserValidator -t wa_users -d mysql -s crud -o laravel -f ``` -------------------------------- ### Quick Start: Managing Permissions and Policies Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/casbin.md Demonstrates how to add permissions and roles for users, and define policies for roles using the Permission facade. ```php use webman\permission\Permission; // adds permissions to a user Permission::addPermissionForUser('eve', 'articles', 'read'); // adds a role for a user. Permission::addRoleForUser('eve', 'writer'); // adds permissions to a rule Permission::addPolicy('writer', 'articles','edit'); ``` -------------------------------- ### Install WeChat SDK Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/wechat.md Install the WeChat SDK using Composer. This command adds the necessary package to your project. ```php composer require w7corp/easywechat ``` -------------------------------- ### Install Webman OpenAI Composer Package Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/response.md Install the webman/openai composer package to integrate with large language models. ```bash composer require webman/openai ``` -------------------------------- ### Install Event Loop for Fiber Coroutines Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/upgrade/1-5.md Install the revolt/event-loop package, which is required for Fiber coroutines when using workerman v5. ```bash composer require revolt/event-loop ^1.0.0 ``` -------------------------------- ### Manual Instantiation vs. Container Instantiation Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/di.md Demonstrates how to correctly obtain service instances using `support\Container` for dependency injection, contrasting with manual instantiation using `new` which does not support injection. ```php use app\service\UserService; use app\service\LogService; use support\Container; // Instances created with new cannot use dependency injection $user_service = new UserService; // Instances created with new cannot use dependency injection $log_service = new LogService($path, $name); // Instances created with Container can use dependency injection $user_service = Container::get(UserService::class); // Instances created with Container can use dependency injection $log_service = Container::make(LogService::class, [$path, $name]); ``` -------------------------------- ### Non-blocking HTTP Requests Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/upgrade/1-5.md Shows how to make non-blocking HTTP GET requests using Workerman's HttpClient. Ensure the http-client package is installed. ```php get('http://example.com'); // Synchronously initiates an asynchronous request return $response->getBody()->getContents(); } } ``` -------------------------------- ### Get Requested Application Name Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md The `app` property returns the name of the requested application. For single-application setups or closure routes, it returns an empty string. ```php $request->app; ``` -------------------------------- ### Example .env file Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/env.md Create a .env file in the project root to store environment-specific variables. ```dotenv DB_HOST = 127.0.0.1 DB_PORT = 3306 DB_NAME = test DB_USER = foo DB_PASSWORD = 123456 ``` -------------------------------- ### Building a Response Object Step-by-Step Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/response.md Demonstrates creating a `Response` object and then setting cookies, headers, and the response body using its methods. Useful for complex responses. ```php public function hello(Request $request) { // Create an object $response = response(); // .... Business logic omitted // Set cookie $response->cookie('foo', 'value'); // .... Business logic omitted // Set http headers $response->header('Content-Type', 'application/json'); $response->withHeaders([ 'X-Header-One' => 'Header Value 1', 'X-Header-Tow' => 'Header Value 2', ]); // .... Business logic omitted // Set the data to be returned $response->withBody('Returned data'); return $response; } ``` -------------------------------- ### Basic MongoDB CRUD Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/mongo.md Perform basic insert and get operations on a MongoDB collection using the Db facade. Ensure the 'mongodb' connection is configured. ```php table('test')->insert([1,2,3]); return json(Db::connection('mongodb')->table('test')->get()); } } ``` -------------------------------- ### Install Redis Extension for Rate Limiter Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/rate-limiter.md Install the necessary Redis extension and component using Composer. This is required for the redis rate limiter driver. ```bash composer require -W webman/redis illuminate/events ``` -------------------------------- ### Using the Database Connection Pool in a Controller Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/coroutine/coroutine.md This example shows how to use the `Db` class, which utilizes a connection pool, to query the database within a webman controller. It demonstrates a simple GET request that fetches the current database time. ```php fetchAll(); return json($value); // [{"now":"2025-02-06 23:41:03","0":"2025-02-06 23:41:03"}] } } ``` -------------------------------- ### Get Entire GET Parameters Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md Retrieve all GET parameters sent with the request. Returns an empty array if no GET parameters are present. ```php $request->get(); ``` -------------------------------- ### Get All POST and GET Inputs Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md Retrieve a combined collection of all POST and GET parameters. ```php $request->all(); ``` -------------------------------- ### Plugin Database Configuration Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/plugin/app.md Shows how to define database connections within a plugin's `config/database.php` file. Multiple connections can be defined. ```php return [ 'default' => 'mysql', 'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'database' => 'database_name', 'username' => 'username', 'password' => 'password', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ], 'admin' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'database' => 'database_name', 'username' => 'username', 'password' => 'password', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ], ], ]; ``` -------------------------------- ### Get Specific GET Parameter Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md Retrieve a specific GET parameter by its name. Returns null if the parameter is not found. ```php $request->get('name'); ``` -------------------------------- ### Get GET Parameter with Default Value Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md Retrieve a specific GET parameter, providing a default value to return if the parameter is not found. ```php $request->get('name', 'tom'); ``` -------------------------------- ### Overwrite GET Parameters Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md Use `setGet()` to overwrite all existing GET parameters with a new array. This method replaces the entire GET parameter collection. ```php $request->get(); // Assume result is ['name' => 'tom', 'age' => 18] $request->setGet(['name' => 'tom']); $request->get(); // Final result is ['name' => 'tom'] ``` -------------------------------- ### Example Language Pack Structure Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/translation.md Illustrates the default directory structure for storing language files. ```text resource/ └── translations ├── en │ └── messages.php └── zh_CN └── messages.php ``` -------------------------------- ### Switching Cache Stores Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/cache.md Demonstrates how to explicitly select and use a specific cache store like 'redis' or 'array'. ```php Cache::store('redis')->set('key', 'value'); Cache::store('array')->set('key', 'value'); ``` -------------------------------- ### Database Configuration Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/tutorial.md Configure default database connection and specific connection details including host, port, credentials, and connection pool settings. The 'options.PDO::ATTR_EMULATE_PREPARES' should be set to false when using swoole or swow as runtime. ```php 'mysql', // Database connection configurations 'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'database' => 'test', 'username' => 'root', 'password' => '', 'unix_socket' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, 'options' => [ PDO::ATTR_EMULATE_PREPARES => false, // Required when using swoole or swow as runtime ], 'pool' => [ // Connection pool configuration 'max_connections' => 5, // Maximum number of connections 'min_connections' => 1, // Minimum number of connections 'wait_timeout' => 3, // Maximum time to wait for a connection from the pool; throws an exception on timeout. Only effective in coroutine environment 'idle_timeout' => 60, // Maximum idle time for connections in the pool; connections are closed and reclaimed after timeout until count reaches min_connections 'heartbeat_interval' => 50, // Connection pool heartbeat interval in seconds; recommended to be less than 60 ], ], ], ]; ``` -------------------------------- ### Install vlucas/phpdotenv Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/env.md Install the vlucas/phpdotenv component using Composer. ```bash composer require vlucas/phpdotenv ``` -------------------------------- ### HTML Template for View Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/response.md An example HTML file (`app/view/foo/hello.html`) that can be rendered by the `view` helper function, demonstrating how to display dynamic data. ```html webman hello ``` -------------------------------- ### Install aop-integration Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/aop.md Install the aop-integration package using Composer. ```shell composer require "hyperf/aop-integration: ^1.1" ``` -------------------------------- ### Install Webman Validation Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/validation.md Install the webman/validation component using composer. ```bash composer require webman/validation ``` -------------------------------- ### Database Configuration Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/config.md Defines multiple database connections including default MySQL, a second MySQL instance, and a PostgreSQL connection within the `config/database.php` file. ```php return [ // Default database 'default' => 'mysql', // Various database configurations 'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'database' => 'webman', 'username' => 'webman', 'password' => '', 'unix_socket' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ], 'mysql2' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'database' => 'webman2', 'username' => 'webman2', 'password' => '', 'unix_socket' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ], 'pgsql' => [ 'driver' => 'pgsql', 'host' => '127.0.0.1', 'port' => 5432, 'database' => 'webman', 'username' => 'webman', 'password' => '', 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', 'sslmode' => 'prefer', ], ]; ``` -------------------------------- ### Install Crontab Component Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/crontab.md Install the workerman/crontab component using composer. ```php composer require workerman/crontab ``` -------------------------------- ### Return a View Response Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/tutorial.md Configure a controller to render a view. This example uses the default native PHP template engine. Ensure the view file exists in the appropriate directory. ```php get('name', $default_name); return view('user/hello', ['name' => $name]); } } ``` ```html webman hello ``` -------------------------------- ### Switching Database Connections Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/config.md Demonstrates how to select and use different database connections (default, 'mysql2', 'pgsql') for querying data. ```php // Use default database, equivalent to Db::connection('mysql')->table('users')->where('name', 'John')->first(); $users = Db::table('users')->where('name', 'John')->first(); // Use mysql2 $users = Db::connection('mysql2')->table('users')->where('name', 'John')->first(); // Use pgsql $users = Db::connection('pgsql')->table('users')->where('name', 'John')->first(); ``` -------------------------------- ### Basic Controller Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/controller.md Defines a simple controller with two actions, 'index' and 'hello'. Accessing '/foo' maps to 'index', and '/foo/hello' maps to 'hello'. ```php true`. This tells the framework to load configurations from this directory. ```php true, ]; ``` -------------------------------- ### Install workerman/validation Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/validation.md Installs the workerman/validation library using Composer. This is a prerequisite for using the Respect/Validation based validator. ```bash composer require workerman/validation ``` -------------------------------- ### Payment Configuration File Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/payment.md Example configuration file for the Payment SDK, supporting Alipay and WeChat. Adjust paths and credentials as needed. The Alipay sandbox mode is demonstrated. ```php [ 'default' => [ // Required - Alipay assigned app_id 'app_id' => '20160909004708941', // Required - Application private key (string or path) 'app_secret_cert' => 'MIIEpAIBAAKCxxxxxxxxxxxxxxP4r3m4OUmD/+XDgCg==', // Required - Application public key certificate (path) 'app_public_cert_path' => base_path().'/payment/appCertPublicKey_2016090900470841.crt', // Required - Alipay public key certificate (path) 'alipay_public_cert_path' => base_path().'/payment/alipayCertPublicKey_RSA2.crt', // Required - Alipay root certificate (path) 'alipay_root_cert_path' => base_path().'/payment/alipayRootCert.crt', // Optional - Synchronous callback address 'return_url' => 'https://webman.tinywan.cn/payment/alipay-return', // Optional - Asynchronous callback address 'notify_url' => 'https://webman.tinywan.cn/payment/alipay-notify', // Optional - Service provider id in service provider mode, used when mode is Pay::MODE_SERVICE 'service_provider_id' => '', // Optional - Default is normal mode. Options are: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE 'mode' => \Yansongda\Pay\Pay::MODE_SANDBOX, ] ], 'wechat' => [ 'default' => [ // Required - Merchant number, service provider mode is service provider merchant number 'mch_id' => '', // Required - Merchant secret key 'mch_secret_key' => '', // Required - Merchant private key (string or path) 'mch_secret_cert' => '', // Required - Merchant public key certificate path 'mch_public_cert_path' => '', // Required 'notify_url' => 'https://yansongda.cn/wechat/notify', // Optional - app_id of the public account 'mp_app_id' => '2016082000291234', // Optional - app_id of the mini program 'mini_app_id' => '', // Optional - app_id of the app 'app_id' => '', // Optional - combine app_id 'combine_app_id' => '', // Optional - combine merchant number 'combine_mch_id' => '', // Optional - app_id of the sub public account in service provider mode 'sub_mp_app_id' => '', // Optional - app_id of the sub app in service provider mode 'sub_app_id' => '', // Optional - app_id of the sub mini program in service provider mode 'sub_mini_app_id' => '', // Optional - sub merchant id in service provider mode 'sub_mch_id' => '', // Optional - WeChat public key certificate path, optional. Strongly recommend configuring this parameter in php-fpm mode 'wechat_public_cert_path' => [ '45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatPublicKey.crt', ], // Optional - Default is normal mode. Options are: MODE_NORMAL, MODE_SERVICE 'mode' => \Yansongda\Pay\Pay::MODE_SANDBOX, ] ], 'logger' => [ 'enable' => false, 'file' => runtime_path().'/logs/alipay.log', 'level' => 'debug', // Suggest adjusting to 'info' in production environment, and 'debug' in development environment 'type' => 'single', // Optional, available options are daily. 'max_file' => 30, // Optional, valid when type is daily, default is 30 days ], 'http' => [ // Optional 'timeout' => 5.0, 'connect_timeout' => 5.0, // For more configuration options, please refer to [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html) ], '_force' => true, ]; ``` -------------------------------- ### Initialize Payment SDK Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/payment.md Initialize the Payment SDK by calling the `config` method with your payment configuration. Ensure the configuration file is correctly loaded. ```php // Get the configuration file config/payment.php $config = Config::get('payment'); Pay::config($config); ``` -------------------------------- ### Package Webman Project Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/others/bin.md Run the build command to package the current Webman project into a binary file. ```bash php webman build:bin ``` -------------------------------- ### Using Different Cache Stores Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/db/thinkcache.md Shows how to explicitly select and use a different cache store, such as Redis, via the Cache facade. This allows for managing caches across different storage backends. ```php // Use different cache stores $redis = Cache::store('redis'); $redis->set('var','value',600); $redis->get('var'); ``` -------------------------------- ### Create a Local Application Plugin Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/app/create.md Use the webman console command to create a new local application plugin. Replace '{plugin_identifier}' with your desired unique identifier. ```bash php webman app-plugin:create {plugin_identifier} ``` -------------------------------- ### Get Server's Local IP Address Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md Use `getLocalIp()` to get the IP address of the server handling the request. ```php $request->getLocalIp(); ``` -------------------------------- ### Plugin Directory Structure Example Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/app/directory.md Illustrates the typical directory layout for a webman plugin, mirroring the core webman application structure. ```text plugin/ └── foo ├── app │ ├── controller │ │ └── IndexController.php │ ├── exception │ │ └── Handler.php │ ├── functions.php │ ├── middleware │ ├── model │ └── view │ └── index │ └── index.html ├── config │ ├── app.php │ ├── autoload.php │ ├── container.php │ ├── database.php │ ├── exception.php │ ├── log.php │ ├── middleware.php │ ├── process.php │ ├── redis.php │ ├── route.php │ ├── static.php │ ├── thinkorm.php │ ├── translation.php │ └── view.php ├── public └── api ``` -------------------------------- ### Get Partial Input Data (POST/GET) Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/request.md Extract specific fields or exclude certain fields from the combined POST and GET parameters. ```php // Get an array of username and password, ignoring the key if it does not exist $only = $request->only(['username', 'password']); // Get all inputs except 'avatar' and 'age' $except = $request->except(['avatar', 'age']); ``` -------------------------------- ### Test Application Configuration Source: https://github.com/webman-php/webman-manual/blob/master/resource/doc/en/components/unitest.md A sample test case for verifying the application's configuration settings. It checks if 'app' configuration is an array and contains specific keys with correct types. ```php time(), 'total_amount' => '8888.88', 'subject' => 'webman payment', '_method' => 'get' // Use the GET method for redirection ]; return Pay::alipay()->web($order)->getBody()->getContents(); } ```