PHP code example of fresns / cmd-word-manager

1. Go to this page and download the library: Download fresns/cmd-word-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fresns / cmd-word-manager example snippets


// Generate cmd word providers: /app/Providers/CmdWordServiceProvider.php
php artisan make:cmd-word-provider

// Generate a cmd word provider for the specified name or directory
php artisan make:cmd-word-provider [Name] [--path Name]

php artisan make:cmd-word-provider FooBar --path Demo
// path directory: /demo/FooBar/Providers/CmdWordServiceProvider.php



return [
    <...>
    'providers' => [
        <...>
        App\Providers\CmdWordServiceProvider::class,
    ],
    <...>
];



namespace App\Providers;

use Plugins\BarBaz\Models\TestModel;
use Plugins\BarBaz\Services\AWordService;
use Plugins\BarBaz\Services\BWordService;

class CmdWordServiceProvider extends ServiceProvider implements \Fresns\CmdWordManager\Contracts\CmdWordProviderContract
{
    <...>
    protected $fsKeyName = 'FooBar';

    protected $cmdWordsMap = [
        ['word' => 'test', 'provider' => [AWordService::class, 'handleTest']],
        ['word' => 'staticTest', 'provider' => [BWordService::class, 'handleStaticTest']],
        ['word' => 'modelTest', 'provider' => [TestModel::class, 'handleModelTest']],
    ];
    <...>
}

// $parameter list = (parameter array);
$wordBody = [
    "email" => "Mail address",
    "title" => "Mail title",
    "content" => "Mail content"
];

// \facades::plugin('plugin name')->cmd word($parameter list): Define the contract for the return object
\FresnsCmdWord::plugin('FresnsEmail')->sendEmail($wordBody);

\FresnsCmdWord::plugin('FresnsEmail')->sendEmail([
    "email" => "Mail address",
    "title" => "Mail title",
    "content" => "Mail content"
]);

$fresnsResp = \FresnsCmdWord::plugin('FresnsEmail')->sendEmail($wordBody);

if ($fresnsResp->isErrorResponse()) {
    return $fresnsResp->getErrorResponse();
}

$fresnsResp->getOrigin(); // Obtaining raw data(code+message+data)

$fresnsResp->getCode(); // Get code only
$fresnsResp->getMessage(); // Get only the message
$fresnsResp->getData(); // Get only the full amount of data
$fresnsResp->getData('user.nickname'); // Get only the parameters specified in data, for example: data.user.nickname

$fresnsResp->isSuccessResponse(); // Determine if the request is true
$fresnsResp->isErrorResponse(); // Determine if the request is false

$fresnsResp->getErrorResponse(); // Internal use returns raw data, API calls return JSON.