Skip to content

emka.web.id

Menu
  • Home
  • Indeks Artikel
  • Tutorial
  • Tentang Kami
Menu

Membuat Aplikasi CLI/Console dengan PHP

Posted on April 11, 2019 by Syauqi Wiryahasana
Bagi yang pernah tahu Laravel, Symphony, Yii atau framework besar lain yang memiliki fitur interaksi di console (terminal/command line), mungkin pernah bertanya, bisakah kita memiliki fitur tersebut tanpa memakai framework-framework diatas? Bisa dong. Salah satu library PHP yang bisa kita gunakan untuk membuat aplikasi CLI (command line interface) yaitu Garden-CLI dari om Vanilla https://github.com/vanilla/garden-cli

Cara Instalasi

Instalasi dengan mudah ke aplikasi existing kita, dengan Composer: [sourcecode]composer require vanilla/garden-cli[/sourcecode]

Contoh Penggunaan

Contoh penggunaan Garden-CLI antara lain: [sourcecode] <?php // All of the command line classes are in the Garden\Cli namespace. use Garden\Cli\Cli; // Require composer's autoloader. require_once 'vendor/autoload.php'; // Define the cli options. $cli = new Cli(); $cli->description('Dump some information from your database.') ->opt('host:h', 'Connect to host.', true) ->opt('port:P', 'Port number to use.', false, 'integer') ->opt('user:u', 'User for login if not current user.', true) ->opt('password:p', 'Password to use when connecting to server.') ->opt('database:d', 'The name of the database to dump.', true); // Parse and return cli args. $args = $cli->parse($argv, true); [/sourcecode] untuk menjalankannya, silakan tambahkan opsi --help untuk menampilkan keterangan aplikasi.
Seedbacklink

Recent Posts

TENTANG EMKA.WEB>ID

EMKA.WEB.ID adalah blog seputar teknologi informasi, edukasi dan ke-NU-an yang hadir sejak tahun 2011. Kontak: kontak@emka.web.id.

©2024 emka.web.id Proudly powered by wpStatically