### Install PHP CSS Parser using Composer Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/sabberworm/php-css-parser/README.md Install the library using Composer. This is the recommended method for managing dependencies. ```bash composer require sabberworm/php-css-parser ``` -------------------------------- ### Iterative Promise Chaining in PHP Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Demonstrates how Guzzle Promises handles 'infinite' then chaining iteratively by shuffling pending handlers between promises, maintaining a constant stack size. This example requires the Guzzle HTTP client and its Promises component to be installed via Composer. ```php then(function ($v) { // The stack size remains constant (a good thing) echo xdebug_get_stack_depth() . ', '; return $v + 1; }); } $parent->resolve(0); var_dump($p->wait()); // int(1000) ``` -------------------------------- ### Install ZipStream-PHP with Composer Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/maennchen/zipstream-php/README.md Use this command to add the maennchen/zipstream-php package to your project's dependencies. ```bash composer require maennchen/zipstream-php ``` -------------------------------- ### Install overtrue/socialite Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Install the overtrue/socialite package using Composer. ```shell $ composer require "overtrue/socialite" -vvv ``` -------------------------------- ### Install Dompdf with Composer Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/dompdf/dompdf/README.md Use Composer to manage Dompdf and its dependencies. Ensure the Composer autoloader is included early in your project. ```bash composer require dompdf/dompdf ``` ```php // somewhere early in your project's loading, require the Composer autoloader // see: http://getcomposer.org/doc/00-intro.md require 'vendor/autoload.php'; ``` -------------------------------- ### Install Dompdf and Dependencies with Git Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/dompdf/dompdf/README.md Manually clone Dompdf and its required libraries (php-font-lib, php-svg-lib, PHP-CSS-Parser) using Git. Specific versions are checked out for compatibility. ```sh git clone https://github.com/dompdf/dompdf.git cd dompdf/lib git clone https://github.com/PhenX/php-font-lib.git php-font-lib cd php-font-lib git checkout 0.5.1 cd .. git clone https://github.com/PhenX/php-svg-lib.git php-svg-lib cd php-svg-lib git checkout v0.3.2 cd .. git clone https://github.com/sabberworm/PHP-CSS-Parser.git php-css-parser cd php-css-parser git checkout 8.1.0 ``` -------------------------------- ### Get User from Access Token Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Use `userFromToken` to retrieve user information directly using a pre-obtained access token. ```php $accessToken = 'xxxxxxxxxxx'; $user = $socialite->userFromToken($accessToken); ``` -------------------------------- ### Handle GitHub Callback and Get User Info Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Process the callback from GitHub after user authorization. Use the provided code to exchange for user information, including the access token. ```php [ 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], ]; $socialite = new SocialiteManager($config); $code = request()->query('code'); $user = $socialite->create('github')->userFromCode($code); $user->getId(); // 1472352 $user->getNickname(); // "overtrue" $user->getUsername(); // "overtrue" $user->getName(); // "安正超" $user->getEmail(); // "anzhengchao@gmail.com" ... ``` -------------------------------- ### Redirecting with a State Parameter Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Include a state parameter in OAuth requests to prevent CSRF attacks. This example uses a hashed session ID as the state. ```php create('github')->withState($state)->redirect(); return redirect($url); ``` -------------------------------- ### Get User from Access Token Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md This method allows you to retrieve user information directly using an access token. This is useful when you already have an access token and do not need to go through the authorization code flow. ```APIDOC ## Get User from Access Token ### Description Retrieve user information directly using an access token. ### Method ```php $accessToken = 'xxxxxxxxxxx'; $user = $socialite->userFromToken($accessToken); ``` ### Response Example (User Object) (The response structure is similar to the `userFromCode` method, containing user details and token information if available.) ``` -------------------------------- ### Get Raw API Response Data Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md The `getRaw()` method returns the complete, unprocessed array response from the OAuth API. ```php $user->getRaw() ``` -------------------------------- ### Get User from OAuth Code Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Use `userFromCode` to retrieve user information after obtaining an authorization code from an OAuth provider. This method returns a User object. ```php $user = $socialite->create('github')->userFromCode($code); ``` -------------------------------- ### Get Token Response Data Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md The `getTokenResponse()` method returns the raw array response from the token acquisition API when using `userFromCode()`. It returns null if `userFromToken()` is used. ```php $user->getTokenResponse() ``` -------------------------------- ### Get User from Authorization Code Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md This method allows you to retrieve user information by providing an authorization code obtained from an OAuth provider. It returns a User object that contains user details and token information. ```APIDOC ## Get User from Authorization Code ### Description Retrieve user information using an authorization code. ### Method ```php $user = $socialite->create('github')->userFromCode($code); ``` ### Response Example (User Object) ```json { "id": 1472352, "nickname": "overtrue", "name": "安正超", "email": "anzhengchao@gmail.com", "avatar": "https://avatars.githubusercontent.com/u/1472352?v=3", "raw": { "login": "overtrue", "id": 1472352, "avatar_url": "https://avatars.githubusercontent.com/u/1472352?v=3", "gravatar_id": "", "url": "https://api.github.com/users/overtrue", "html_url": "https://github.com/overtrue", ... }, "token_response": { "access_token": "5b1dc56d64fffbd052359f032716cc4e0a1cb9a0", "token_type": "bearer", "scope": "user:email" } } ``` ### Accessing User Attributes User attributes can be accessed like array keys or via object methods. #### Array Access ```php $user['id']; // 1472352 $user['nickname']; // "overtrue" $user['name']; // "安正超" $user['email']; // "anzhengchao@gmail.com" ... ``` #### Object Methods ```php mixed $user->getId(); ?string $user->getNickname(); ?string $user->getName(); ?string $user->getEmail(); ?string $user->getAvatar(); ?string $user->getRaw(); ?string $user->getAccessToken(); ?string $user->getRefreshToken(); ?int $user->getExpiresIn(); ?array $user->getTokenResponse(); ``` ### Raw Data - `$user->getRaw()`: Returns the raw OAuth API response as an array. - `$user->getTokenResponse()`: Returns the token response from the OAuth API as an array. This method returns a valid array only when using `userFromCode()`; otherwise, it returns `null`. ``` -------------------------------- ### Configure Douyin Authentication Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Set up your app ID, app secret, and redirect URL for Douyin authentication. This snippet demonstrates obtaining user information via authorization code or by using an access token with an open ID. ```php $config = [ 'douyin' => [ 'client_id' => 'your app id', 'client_secret' => 'your app secret', 'redirect' => 'redirect URL' ] ]; $socialite = new SocialiteManager($config); $user = $socialite->create('douyin')->userFromCode('here is auth code'); $user = $socialite->create('douyin')->withOpenId('openId')->userFromToken('here is the access token'); ``` -------------------------------- ### Configure Alipay Authentication Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Set up your application ID, RSA2 private key, and redirect URL for Alipay authentication. This snippet demonstrates how to initialize Socialite and obtain user information using an authorization code. ```php $config = [ 'alipay' => [ // 这个键名还能像官方文档那样叫做 'app_id' 'client_id' => 'your-app-id', // 请根据官方文档,在官方管理后台配置 RSA2 // 注意: 这是你自己的私钥 // 注意: 不允许私钥内容有其他字符 // 建议: 为了保证安全,你可以将文本信息从磁盘文件中读取,而不是在这里明文 'rsa_private_key' => 'your-rsa-private-key', // 确保这里的值与你在服务后台绑定的地址值一致 // 这个键名还能像官方文档那样叫做 'redirect_url' 'redirect' => 'http://localhost/socialite/callback.php', ] ... ]; $socialite = new SocialiteManager($config); $user = $socialite->create('alipay')->userFromCode('here is auth code'); // 详见文档后面 "User interface" $user->getId(); // 1472352 $user->getNickname(); // "overtrue" $user->getUsername(); // "overtrue" $user->getName(); // "安正超" ... ``` -------------------------------- ### Apache Web Server Configuration Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码指南.md Apache服务器的独立部署配置,包括SSL模块、重写模块的加载,以及public目录的访问权限和虚拟主机设置。 ```apache LoadModule ssl_module modules/mod_ssl.so LoadModule rewrite_module modules/mod_rewrite.so Options FollowSymLinks AllowOverride All Require all granted DirectoryIndex index.php index.html DocumentRoot "代码所在目录\public" ServerName 服务域名 ``` -------------------------------- ### Apache Web Server Configuration Source: https://github.com/bonyren/wzy-xl/wiki/《为之易心理健康平台》独立部署指南 Required Apache configuration for the platform deployment. Ensure 'mod_ssl' and 'mod_rewrite' modules are loaded and the DocumentRoot is correctly set to the '/public' directory. ```apache LoadModule ssl_module modules/mod_ssl.so LoadModule rewrite_module modules/mod_rewrite.so Options FollowSymLinks AllowOverride All Require all granted DirectoryIndex index.php index.html DocumentRoot "代码所在目录\public" ServerName 服务域名 ``` -------------------------------- ### Nginx + php-fpm Web Server Configuration Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码指南.md Nginx服务器与php-fpm配合的独立部署配置,包括监听端口、服务器名称、网站根目录、URL重写规则以及PHP文件处理的FastCGI参数设置。 ```nginx server { listen 80; server_name 服务域名; root 代码所在目录/public; location / { index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } location ~ \.php(.*)$ { fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+); fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } client_max_body_size 30M; } ``` -------------------------------- ### Configure Multiple Socialite Providers Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Configure settings for multiple social platforms like Weibo and Facebook. Ensure 'client_id', 'client_secret', and 'redirect' are set for each provider. ```php $config = [ 'weibo' => [ 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], 'facebook' => [ 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], ]; ``` -------------------------------- ### Dynamically Setting Redirect URL Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md The `redirect()` method can accept a URL to dynamically set the callback URI. Alternatively, use the `withRedirectUrl()` method before calling `redirect()`. ```php $url = 'your callback url.'; $socialite->redirect($url); // or $socialite->withRedirectUrl($url)->redirect(); ``` -------------------------------- ### Registering Callbacks with a Promise Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Register fulfillment and rejection callbacks for a promise using the `then` method. Callbacks are triggered when the promise is resolved. ```php use GuzzleHttp\Promise\Promise; $promise = new Promise(); $promise->then( // $onFulfilled function ($value) { echo 'The promise was fulfilled.'; }, // $onRejected function ($reason) { echo 'The promise was rejected.'; } ); ``` -------------------------------- ### Update Request Options Configuration Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/guzzle/UPGRADING.md Migrate from deprecated command-specific options like 'command.headers' and 'command.response_body' to the new 'command.request_options' array for configuring request options. ```php $command = $client->getCommand('foo', array( 'command.headers' => array('Test' => '123'), 'command.response_body' => '/path/to/file' )); // Should be changed to: $command = $client->getCommand('foo', array( 'command.request_options' => array( 'headers' => array('Test' => '123'), 'save_as' => '/path/to/file' ) )); ``` -------------------------------- ### Synchronously Resolve a Promise Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Create a promise and immediately resolve it with a value. Calling `wait` will return the resolved value. ```php $promise = new Promise(function () use (&$promise) { $promise->resolve('foo'); }); // Calling wait will return the value of the promise. echo $promise->wait(); // outputs "foo" ``` -------------------------------- ### Render PHP CSS Structure to CSS Output Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/sabberworm/php-css-parser/README.md Demonstrates rendering the parsed CSS object structure back into a compact CSS string. This is useful for outputting modified or original CSS. ```php parse(); // Render the CSS document back to a string $outputCss = $document->render(); // Output the rendered CSS echo $outputCss; ?> ``` ```css #header {margin: 10px 2em 1cm 2%;font-family: Verdana,Helvetica,"Gill Sans",sans-serif;color: red !important;} ``` -------------------------------- ### Parse CSS from a String Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/sabberworm/php-css-parser/README.md Create a new Parser instance with a CSS string and parse it into a CSS document structure. ```php $parser = new \Sabberworm\CSS\Parser($css); $cssDocument = $parser->parse(); ``` -------------------------------- ### Including Additional Optional Parameters Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Pass any optional parameters required by the OAuth provider using the `with()` method, providing an associative array of key-value pairs. ```php $response = $socialite->create('google') ->with(['hd' => 'example.com'])->redirect(); ``` -------------------------------- ### Authorize User with GitHub Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Redirect users to the GitHub authorization page to initiate the OAuth flow. Ensure your configuration includes client ID, client secret, and redirect URI. ```php [ 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], ]; $socialite = new SocialiteManager($config); $url = $socialite->create('github')->redirect(); return redirect($url); ``` -------------------------------- ### Parse CSS from a File Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/sabberworm/php-css-parser/README.md Read CSS content from a file using `file_get_contents` and then parse it with the CSS Parser. ```php $parser = new \Sabberworm\CSS\Parser(file_get_contents('somefile.css')); $cssDocument = $parser->parse(); ``` -------------------------------- ### Promise as a Deferred Value in PHP Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Illustrates the pattern where a promise object also acts as its own deferred value, allowing direct resolution or rejection of the promise. This is useful for consumers who need to control the outcome of a promise they created. ```php $promise = new Promise(); $promise->then(function ($value) { echo $value; }); // The promise is the deferred value, so you can deliver a value to it. $promise->resolve('foo'); // prints "foo" ``` -------------------------------- ### Enable Deprecation Warnings Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/guzzle/UPGRADING.md Enable E_USER_DEPRECATED warnings to identify the usage of deprecated methods in Guzzle. ```php \Guzzle\Common\Version::$emitWarnings = true; ``` -------------------------------- ### Verifying the State Parameter in Callback Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md After user authorization, verify that the state parameter returned by the OAuth server matches the state generated by your application to ensure request integrity. ```php query('state'); $code = request()->query('code'); // Check the state received with current session id if ($state != hash('sha256', session_id())) { exit('State does not match!'); } $user = $socialite->create('github')->userFromCode($code); // authorized ``` -------------------------------- ### Rejecting a Promise Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Reject a promise using the `reject` method. This invokes the registered onRejected callbacks with the provided reason. ```php use GuzzleHttp\Promise\Promise; $promise = new Promise(); $promise->then(null, function ($reason) { echo $reason; }); $promise->reject('Error!'); // Outputs "Error!" ``` -------------------------------- ### Extend Socialite with Custom Provider via Creator Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Extend Socialite with a custom provider by using the `extend` method with a closure. This is useful when the provider is not yet supported by the library. ```php $config = [ 'foo' => [ 'provider' => 'myprovider', // <-- 一个工具还未支持的服务提供程序 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], ]; $socialite = new SocialiteManager($config); $socialite->extend('myprovider', function(array $config) { return new MyCustomProvider($config); }); $app = $socialite->create('foo'); ``` -------------------------------- ### Access User Attributes via Methods Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Use getter methods on the User object to retrieve specific attributes. ```php mixed $user->getId(); ?string $user->getNickname(); ?string $user->getName(); ?string $user->getEmail(); ?string $user->getAvatar(); ?string $user->getRaw(); ?string $user->getAccessToken(); ?string $user->getRefreshToken(); ?int $user->getExpiresIn(); ?array $user->getTokenResponse(); ``` -------------------------------- ### Extend Socialite with Custom Provider Class Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Extend Socialite by specifying a custom provider class in the configuration. The custom provider class must implement the `Overtrue\Socialite\Contracts\ProviderInterface` interface. ```php $config = [ 'foo' => [ 'provider' => MyCustomProvider::class, // <-- 类名 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], ]; $socialite = new SocialiteManager($config); $app = $socialite->create('foo'); ``` -------------------------------- ### Rejection Forwarding with Exceptions Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md If an exception is thrown within an onRejected callback, subsequent onRejected callbacks in the chain are invoked with that exception as the reason. ```php use GuzzleHttp\Promise\Promise; $promise = new Promise(); $promise->then(null, function ($reason) { throw new Exception($reason); })->then(null, function ($reason) { assert($reason->getMessage() === 'Error!'); }); $promise->reject('Error!'); ``` -------------------------------- ### Access User Attributes as Array Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md User attributes can be accessed like array keys for convenience. ```php $user['id']; // 1472352 $user['nickname']; // "overtrue" $user['name']; // "安正超" $user['email']; // "anzhengchao@gmail.com" ... ``` -------------------------------- ### Wait on a Rejected Promise Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Calling `wait` on a rejected promise will throw an exception. If the rejection reason is an `\Exception`, it's thrown directly; otherwise, a `RejectionException` is thrown. ```php $promise = new Promise(); $promise->reject('foo'); $promise->wait(); ``` -------------------------------- ### Generate Baidu OAuth URL with Display Mode Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Generate a Baidu OAuth URL, specifying the display mode for the authorization page. The default display mode is 'page' (full screen). ```php $authUrl = $socialite->create('baidu')->withDisplay('mobile')->redirect(); ``` -------------------------------- ### Include Dompdf Autoloader from Packaged Release Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/dompdf/dompdf/README.md If you downloaded a packaged release of Dompdf, use its autoloader to include the library and its dependencies. ```php // include autoloader require_once 'dompdf/autoload.inc.php'; ``` -------------------------------- ### Rejection Forwarding with RejectedPromise Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md A rejection can be forwarded down the promise chain by returning a `GuzzleHttp Promise RejectedPromise` from either an onFulfilled or onRejected callback. ```php use GuzzleHttp\Promise\Promise; use GuzzleHttp\Promise\RejectedPromise; $promise = new Promise(); $promise->then(null, function ($reason) { return new RejectedPromise($reason); })->then(null, function ($reason) { assert($reason === 'Error!'); }); $promise->reject('Error!'); ``` -------------------------------- ### Configure DingTalk Authentication Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Configure your app ID, app secret, and redirect URL for DingTalk authentication. This snippet shows how to initialize Socialite and retrieve user details using an authorization code. ```php $config = [ 'dingtalk' => [ // or 'app_id' 'client_id' => 'your app id', // or 'app_secret' 'client_secret' => 'your app secret', // or 'redirect_url' 'redirect' => 'redirect URL' ] ]; $socialite = new SocialiteManager($config); $user = $socialite->create('dingtalk')->userFromCode('here is auth code'); // 详见文档后面 "User interface" $user->getId(); // 1472352 $user->getNickname(); // "overtrue" $user->getUsername(); // "overtrue" $user->getName(); // "安正超" ... ``` -------------------------------- ### Configure WeChat Third-Party Platform Authorization Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Configure WeChat for third-party platform web authorization. This snippet shows the necessary configuration parameters including client ID, client secret, redirect URL, and component app ID and token. ```php ... [ 'wechat' => [ 'client_id' => 'client_id', 'client_secret' => 'client_secret', 'redirect' => 'redirect-url', // 开放平台 - 第三方平台所需 'component' => [ // or 'app_id', 'component_app_id' as key 'id' => 'component-app-id', // or 'app_token', 'access_token', 'component_access_token' as key 'token' => 'component-access-token', ] ] ], ... ``` -------------------------------- ### Parse CSS Input to PHP Structure Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/sabberworm/php-css-parser/README.md Shows the internal PHP structure generated after parsing a CSS input string. This structure can be programmatically manipulated. ```css #header { margin: 10px 2em 1cm 2%; font-family: Verdana, Helvetica, "Gill Sans", sans-serif; color: red !important; } ``` ```php parse(); // Output the structure (for demonstration purposes) var_dump($document); ?> ``` -------------------------------- ### Set Default Charset for Parser Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/sabberworm/php-css-parser/README.md Configure the parser to use a specific default charset if no `@charset` declaration is found in the CSS. UTF-8 is the default. ```php $settings = \Sabberworm\CSS\Settings::create() ->withDefaultCharset('windows-1252'); $parser = new \Sabberworm\CSS\Parser($css, $settings); ``` -------------------------------- ### Enable Strict Parsing Mode Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/sabberworm/php-css-parser/README.md Configure the parser to throw an error on invalid CSS rules by enabling strict parsing mode. ```php $parser = new \Sabberworm\CSS\Parser( file_get_contents('somefile.css'), \Sabberworm\CSS\Settings::create()->beStrict() ); ``` -------------------------------- ### Handling Rejection with a Return Value Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md If an onRejected callback does not throw an exception and does not return a rejected promise, its return value is used to fulfill downstream onFulfilled callbacks. ```php use GuzzleHttp\Promise\Promise; $promise = new Promise(); $promise ->then(null, function ($reason) { return "It's ok"; }) ->then(function ($value) { assert($value === "It's ok"); }); $promise->reject('Error!'); ``` -------------------------------- ### Chaining Promises and Forwarding Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Promises can be chained, with the return value of a `then` callback forwarded to the next promise in the chain. Returning a promise from a callback causes subsequent promises to wait for its fulfillment. ```php use GuzzleHttp\Promise\Promise; $promise = new Promise(); $nextPromise = new Promise(); $promise ->then(function ($value) use ($nextPromise) { echo $value; return $nextPromise; }) ->then(function ($value) { echo $value; }); // Triggers the first callback and outputs "A" $promise->resolve('A'); // Triggers the second callback and outputs "B" $nextPromise->resolve('B'); ``` -------------------------------- ### Generate Taobao OAuth URL with View Mode Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Generate a Taobao OAuth URL, specifying the view mode for the redirect page. The default view mode is 'web'. ```php $authUrl = $socialite->create('taobao')->withView('wap')->redirect(); ``` -------------------------------- ### Configure Feishu Internal App Authentication Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Configure Feishu authentication for internal applications by setting the app mode to 'internal'. This snippet shows how to initialize Socialite and authenticate using either internal app mode or default mode with an app ticket. ```php $config = [ 'feishu' => [ // or 'app_id' 'client_id' => 'your app id', // or 'app_secret' 'client_secret' => 'your app secret', // or 'redirect_url' 'redirect' => 'redirect URL', // 如果你想使用使用内部应用的方式获取 app_access_token // 对这个键设置了 'internal' 值那么你已经开启了内部应用模式 'app_mode' => 'internal' ] ]; $socialite = new SocialiteManager($config); $feishuDriver = $socialite->create('feishu'); $feishuDriver->withInternalAppMode()->userFromCode('here is code'); $feishuDriver->withDefaultMode()->withAppTicket('app_ticket')->userFromCode('here is code'); ``` -------------------------------- ### Alias Socialite Providers with Custom Names Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Use aliases for socialite providers by setting a 'provider' key in the configuration. This allows you to manage multiple applications for the same provider under different names. ```php $config = [ // 为 github 应用起别名为 foo 'foo' => [ 'provider' => 'github', // <-- provider name 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], // 另外一个名字叫做 bar 的 github 应用 'bar' => [ 'provider' => 'github', // <-- provider name 'client_id' => 'your-app-id', 'client_secret' => 'your-app-secret', 'redirect' => 'http://localhost/socialite/callback.php', ], //... ]; $socialite = new SocialiteManager($config); $appFoo = $socialite->create('foo'); $appBar = $socialite->create('bar'); ``` -------------------------------- ### Setting Scopes for OAuth Requests Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/overtrue/socialite/README_CN.md Use the `scopes()` method to set specific permissions for an OAuth request. This will override any previously set scopes. ```php $response = $socialite->create('github') ->scopes(['scope1', 'scope2'])->redirect(); ``` -------------------------------- ### Do Not Unwrap Promise State Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md Force a promise to resolve without unwrapping its state by passing `false` to the `wait` function. This ensures the promise is settled but does not throw exceptions or return values directly. ```php $promise = new Promise(); $promise->reject('foo'); // This will not throw an exception. It simply ensures the promise has // been resolved. $promise->wait(false); ``` -------------------------------- ### Handle Exception During Promise Resolution Source: https://github.com/bonyren/wzy-xl/blob/master/独立部署源代码/vendor/guzzlehttp/promises/README.md When a promise's wait function throws an exception, the promise is rejected with that exception, and calling `wait` will re-throw it. ```php $promise = new Promise(function () use (&$promise) { throw new Exception('foo'); }); $promise->wait(); // throws the exception. ```