Skip to content

Instantly share code, notes, and snippets.

@DeRain
Forked from mrdziuban/PsySH_with_Yii.md
Created August 15, 2016 09:39
Show Gist options
  • Save DeRain/555f43a3c39e2baa825d7f2f8aedea8e to your computer and use it in GitHub Desktop.
Save DeRain/555f43a3c39e2baa825d7f2f8aedea8e to your computer and use it in GitHub Desktop.
How to use PsySH with a Yii application
<?php
return array(
'eraseDuplicates' => true,
'historySize' => 100,
);
<?php
ini_set('memory_limit', -1);
$yiidir = dirname(__FILE__).'/../../../yii/framework/';
$appdir = dirname(__FILE__).'/../../';
require_once($yiidir.'yii.php');
error_reporting(E_ALL ^ (E_STRICT|E_NOTICE));
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'] = $yiidir.'index.php';
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_NAME'] = 'localhost';
Yii::createWebApplication($appdir.'config/main.php');
$version = Yii::getVersion();
echo <<<EOD
Yii Interactive Tool v1.1 (based on Yii v{$version})
Please type 'help' for help. Type 'exit' to quit.
EOD;

Using PsySH (GitHub) as the Yii shell

  • Issue the following commands from the command line in your Yii application directory:
    • chmod +x shell
    • mkdir extensions/yiishell
    • wget -O extensions/yiishell/psysh psysh.org/psysh
    • chmod +x extensions/yiishell/psysh
  • Copy the file init.php below to extensions/yiishell/init.php and update any paths to work with your application configuration
  • Copy the file config.php below to extensions/yiishell/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 extensions/yiishell/psysh extensions/yiishell/init.php --config extensions/yiishell/config.php
    • Alternatively, for an easy way to start the shell, copy the shell script below to your application directory, then run ./shell
#!/bin/sh -x
./extensions/yiishell/psysh ./extensions/yiishell/init.php --config ./extensions/yiishell/config.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment