PHP code example of dovetaily / compio

1. Go to this page and download the library: Download dovetaily/compio 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/ */

    

dovetaily / compio example snippets




return [

	/*
	|--------------------------------------------------------------------------
	| The configuration of the Compio(`dovetaily/compio`) Lib.
	|--------------------------------------------------------------------------
	|
	| Customize the way Compio(`dovetaily/compio`) generates your components
	| by adding your own templates or by modifying the way default templates
	| are generated. And you have the possibility to list your components to
	| generate in any configuration file, Compio(`dovetaily/compio`) will
	| generate all your components according to your global and current
	| configuration related to the components.
	|
	*/
	'component' => [
		'config' => [
			'

# For larvel >=5.5

# code ...
class Kernel extends ConsoleKernel
{
	# code ...
		protected function commands()
		{
			# code ...

			# For larvel >=5.5
				

// php artisan compio:component Path/MyComponent string:my_string_type_argument="Default value" array:null:my_array_or_null_type_argument_2= my_argument_ * @var array
     */
	private static $assets = [
		'css' => [
			'css\components\Path\MyComponent.css'
		],
		'js' => [
			'js\components\Path\MyComponent.js'
		],
	];

	// properties...
	public $my_argument_argument_...
			'my_argument_ self::$assets[$key] : false);

	}
}


# code ...
	public function __construct($my_argument_

return [
	// ...
	'component' => [
		'config' => [
			// ...
		]
	]
];

return [
	// ...
	'component' => [
		'config' => [
			// ...
		],
		'datas' => [
			['name' => 'Path/MyComponent',
				'args' => [
					'string:my_string_type_argument' => "Default value", //
					'array:null:my_array_or_null_type_argument_2' => \Compio\Component\Arguments::NULL_VALUE, // set `null` value
					'my_argument_ray` value
					'int:null:like' => \Compio\Component\Arguments::NULL_VALUE,  // set `null` value
					'\Illuminate\Contracts\View\View:\Closure:string:null:more' => \Compio\Component\Arguments::NULL_VALUE  // set `null` value
				]
			],
			['name' => 'Shape/Ball']
		]
	]
];

// ...
namespace App\View\Components\Cards\Post;
class User extends Component
	// code ...
	public function __construct(
		string $title, // '...title' => null, // Mandatory argument
		string|null $description = null, // '...description' => \Compio\Component\Arguments::NULL_VALUE, // default value `null`
		int|null $like = null, // '...like' => \Compio\Component\Arguments::NULL_VALUE, // default value `null`
		array|string $image = array (
			0 => 'http://my.cdn.com/img/21128376.jpg',
			1 => 'http://my_cdn.com/img/44837110.jpg',
		),
		\Illuminate\Contracts\View\View|\Closure|string|null $more = null
	)
	// code ...

return [
	// ...
	'component' => [
		'config' => [
			'template' => [
				'class' => [
					// code ...
				],
				'render' => [
					// code ...
				],
				'css' => [
					// code ...
				],
				'js' => [
					// code ...
				]
			],
			'

'

return [
	// code ...
			'template' => [
				'class' => [
					'path' => getcwd() . '\app\View\Components',
					'template_file' => dirname(__DIR__) . '\resources\component\class.php',
					'generate' => true,
					'convert_case' => 'default',
					'keywords' => [
						'@command',
						'@namespace',
						'@class_name',
						'@locate_css',
						'@locate_js',
						'@locate_render',
						'@args_init',
						'@args_params',
						'@args_construct',
						'@args_render',
					]
				]
			]
	// code ...
]


@command
namespace App\View\Components@namespace;

use Illuminate\View\Component;

class @class_name extends Component
{

    /**
     * The class assets.
     *
     * @var array
     */
	private static $assets = [
		'css' => [@locate_css],
		'js' => [@locate_js],
	];

	// properties...
	@args_init

	/**
	 * Create a new component instance.
	 *
	 * @return void
	 */
	public function __construct(@args_params){

		// properties...
		@args_construct

	}

	/**
	 * Get the view / contents that represent the component.
	 *
	 * @return \Illuminate\Contracts\View\View|\Closure|string
	 */
	public function render()
	{

		return view('@locate_render', [
			// properties...
			@args_render
		]);

	}

	/**
	 * Get component assets
	 *
	 * @param string|null  $key
	 * @return array|string
	 */
	public static function getAssets(string|null $key = null){

		return empty($key) ? self::$assets : (array_key_exists($key, self::$assets) ? self::$assets[$key] : false);

	}
}

// file : '.\my_project\config\compio.php'
// ______________________________________
return [
	// code ...
			'template' => [
				'class' => [
					// code ...
					'keywords' => [
						'@command' => '--- My customize content ---' 
					]
				]
				// code ...
			]
	// code ...
]


// file : '.\my_project\app\View\Components\Path\MyComponent.php'
// ______________________________________________________________

--- My customize content ---
namespace App\View\Components\Path;

use Illuminate\View\Component;

class MyComponent extends Component
// code ...

'@command' => function(array $template_datas, array|null $arguments){
	return '--- My customize content ---';
} 

// If you run the command :
	// php artisan compio:component Path/MyComponent string:my_string_type_argument="Default value" array:null:my_array_or_null_type_argument_2= my_argument_		"extension" => "php",
			"filename" => "MyComponent",
			"file" => "C:\Users\...\my_project\app\View\Components\Path\MyComponent.php"
		]
	],
	"template_file" => "C:\Users\...\my_project\vendor\dovetaily\compio\...", // Template file
	"generate" => true,
	"keywords" => [ // Keyword replaced in template file
		"@command" => function(array $template_datas, array|null $arguments){/*...*/},
		"@namespace" => "\Path",
		"@class_name" => "MyComponent",
		"@locate_css" => "\n\t\t\t'css\components\Path\MyComponent.css'\n\t\t",
		"@locate_css" => "\n\t\t\t'js\components\Path\MyComponent.js'\n\t\t",
		"@locate_render" => "components.Path.MyComponent",
		"@args_init" => "public $my_string_type_argument;\n\tpublic $my_array_or_null_type_argument_2;\n\tpublic $my_argument_

return [
	// code ...
			'template' => [
				// code ...
				'render' => [
					'path' => getcwd() . '\resources\views\components',
					'file_extension' => 'blade.php',
					'short_path' => 'components',
					'template_file' => dirname(__DIR__) . '\resources\component\render.php',
					'generate' => true,
					'keywords' => [
						'@component_name',
						'@class_html',
					]
				]
			]
	// code ...
]

// If you run the command :
	// php artisan compio:component Path/MyComponent string:my_string_type_argument="Default value" array:null:my_array_or_null_type_argument_2= my_argument_=> "PathMycomponent",
		"@class_name" => "path-mycomponent-72h4pk05",
	]
]
$arguments = [
	// code ...
]

return [
	// code ...
			'template' => [
				// code ...
				'css' => [
					'path' => getcwd() . '\public\css\components',
					'file_extension' => 'css',
					'short_path' => 'css\components',
					'template_file' => dirname(__DIR__) . '\resources\component\css.php',
					'generate' => true,
					'keywords' => [
						'@class_html',
					]
				]
			]
	// code ...
]

return [
	// code ...
			'template' => [
				// code ...
				'js' => [
					'path' => getcwd() . '\public\js\components',
					'file_extension' => 'js',
					'short_path' => 'js\components',
					'template_file' => dirname(__DIR__) . '\resources\component\js.php',
					'generate' => true,
					'keywords' => [
						'@class_html',
					]
				]
			]
	// code ...
]

return [
	'component' => [
		'config' => [
			'template' => [
				'my_template' => [
					// late_file' => string, // the template file
						'generate' => bool, // decide if the template should be generated
					// not ate (`.php` by default)
				]
			]
		]
	]
]

return [
	'component' => [
		'config' => [
			'template' => [
				'class' => ['generate' => false],
				'render' => ['generate' => false],
				'css' => ['generate' => false],
				'js' => ['generate' => false],
			]
			// code ...
		]
		// code ...
	]
]

// code ...
'keywords' => [
	'@command',
	'@namespace',
	'@class_name',
	'@locate_css',
	'@locate_js',
	'@locate_render',
	'@args_init',
	'@args_params',
	'@args_construct',
	'@args_render',
	'@component_name',
	'@class_html',
]
// code ...

// If you run the command :
	// php artisan compio:component Path/MyComponent string:my_string_type_argument="Default value" array:null:my_array_or_null_type_argument_2= my_argument_gs[0][My first argument is "{--name--}"]', // Result : My first argument is "my_string_type_argument"
	'@args[1][My argument {--name--} is of type {--type--}]', // Result : My argument my_array_or_null_type_argument_2 is of type array|null
	'@args[2][The value of argument {--name--} is "{--value--}"]', // Result : The value of argument my_argument_uire_3;
	'@args[*][name -> {--name--} type -> {--type--}]', // Result : name -> my_string_type_argument -> string; name -> my_array_or_null_type_argument_2 -> array|null; name -> my_argument_

// code ...
	'component' => [
		'config' => [
			'template' => [
				'my_template' => [
					// code ...
					'keywords' => [ // the keywords to replace in the template
						'@command' => 'My own value', // Changing the default value of this keyword
						'@my_own_keyword', // defaut value `null`
						'@my_own_keyword_2' => function(array $template_datas, array|null $arguments){
							$result = null;
							// code ...
								// ... your runtime code
							return $result;
						}, // 
						'@my_own_keyword_3' => 'My value',
					],
					// code ...
				]
			]
		]
	]
// code ...

return [
	// ...
	'component' => [
		'config' => [
			// ...
		],
		'datas' => [
			['name' => 'Path/MyComponent',
				'args' => [ /*...*/ ],
				'config' => [
					'template' =>
					[
						'class' => [
							// 						// not e (`.php` by default)
						]
					],
					'
json
{
	// code ...
	"scripts": {
		// code ...
		"post-autoload-dump": [
			// code ...
			"Compio\\ComposerScripts::postAutoloadDump"
		]
		// code ...
	}
	// code ...
}
console
$ php artisan list
Laravel Framework ...

Usage:
  ...

Options:
  ...

Available commands:
 ...
 ...
 compio
  compio:component       Advanced component generator Compio(`dovetail/compio`)
 ...
 ...

console
$ php artisan compio:component [<component_name> [<args>...]]
console
$ php artisan compio:component Path/MyComponent string:my_string_type_argument="Default value" array:null:my_array_or_null_type_argument_2= my_argument_p"


		Success | Created : "C:\Path\...\my_project\resources\views\components\Path\MyComponent.blade.php"


		Success | Created : "C:\Path\...\my_project\public\css\components\Path\MyComponent.css"


		Success | Created : "C:\Path\...\my_project\public\js\components\Path\MyComponent.js"


		Component (Path/MyComponent) created successfully !
console
$ php artisan compio:component Path/MyComponent --replace=true