Skip to content

Instantly share code, notes, and snippets.

@cornernote
Created June 4, 2015 12:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cornernote/ccf7e62d965497369185 to your computer and use it in GitHub Desktop.
Save cornernote/ccf7e62d965497369185 to your computer and use it in GitHub Desktop.
How to use PsySH with a Yii2 application

Using PsySH (GitHub) as the Yii2 shell

  • Issue the following commands from the command line in your Yii application directory:
    • chmod +x psyii
    • mkdir extensions/yiishell
    • wget -O extensions/yiishell/psysh psysh.org/psysh
    • chmod +x extensions/yiishell/psysh
  • Copy the file init.php below to psysh/init.php and update any paths to work with your application configuration
  • Copy the file config.php below to psysh/config.php. Change or add to the config array with the options you'd like to use (available options)
  • Now you can start PsySH with the command ./psyii psysh/init.php --config psysh/config.php
    • Alternatively, for an easy way to start the shell, copy the psyii script below to your application directory, then run ./shell

Based on article by mrdziuban for Yii1

<?php
return array(
'eraseDuplicates' => true,
'historySize' => 100,
);
<?php
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../config/env.php');
defined('YII_DEBUG') or define('YII_DEBUG', (boolean)getenv('YII_DEBUG'));
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV'));
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../config/bootstrap.php');
require(__DIR__ . '/../config/main.php');
$application = new yii\console\Application($config);
$version = Yii::getVersion();
echo <<<EOD
PsYii Interactive Tool v2.0 (based on Yii v{$version})
Please type 'help' for help. Type 'exit' to quit.
EOD;
#!/bin/sh -x
psysh ./psysh/init.php --config ./psysh/config.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment