PHPackages                             ramsey/composer-repl-lib - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. ramsey/composer-repl-lib

ActiveLibrary[CLI &amp; Console](/categories/cli)

ramsey/composer-repl-lib
========================

The library behind ramsey/composer-repl, allowing for extension of the ramsey/composer-repl Composer plugin and non-plugin use of the repl command.

1.4.0(2mo ago)294.7k↑72.7%1[2 PRs](https://github.com/ramsey/composer-repl-lib/pulls)2MITPHPPHP ^8.1CI passing

Since Jan 18Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/ramsey/composer-repl-lib)[ Packagist](https://packagist.org/packages/ramsey/composer-repl-lib)[ RSS](/packages/ramsey-composer-repl-lib/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (42)Versions (11)Used By (2)

ramsey/composer-repl-lib
========================

[](#ramseycomposer-repl-lib)

 **The library behind the [ramsey/composer-repl](https://github.com/ramsey/composer-repl) Composer plugin.**

 [![Source Code](https://camo.githubusercontent.com/5c582936251d446296c37a080f56a74c44f6b7a49a8b3a9fdc5e56b1ad6ef47a/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d72616d7365792f636f6d706f7365722d2d7265706c2d2d6c69622d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/ramsey/composer-repl-lib) [![Download Package](https://camo.githubusercontent.com/6100e6e0b32d794b08004a51cc88b245d4aeea8f6abd7b9c033a85104d52b99c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616d7365792f636f6d706f7365722d7265706c2d6c69622e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/ramsey/composer-repl-lib) [![PHP Programming Language](https://camo.githubusercontent.com/9f98219e756834c41b4563bb05a1a65b472fa1a44f52c81f469ce6e302ae03a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616d7365792f636f6d706f7365722d7265706c2d6c69622e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d253233383839324246)](https://php.net) [![Read License](https://camo.githubusercontent.com/095254c8f8a287f6063ebbc41de14fb9ef39f7eee7cb756fa0ba263fd4bf7eac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72616d7365792f636f6d706f7365722d7265706c2d6c69622e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6461726b6379616e)](https://github.com/ramsey/composer-repl-lib/blob/main/LICENSE) [![Build Status](https://camo.githubusercontent.com/e127952496bcd699fa46c14cb01f4560387b6c2a15ec94c8f3159c7955f0242b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72616d7365792f636f6d706f7365722d7265706c2d6c69622f636f6e74696e756f75732d696e746567726174696f6e2e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/ramsey/composer-repl-lib/actions/workflows/continuous-integration.yml) [![Codecov Code Coverage](https://camo.githubusercontent.com/afa53b4ede62e2d5581f9bd865d4a6a58c4b227f75e796da94d7c6c6b96b145d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f72616d7365792f636f6d706f7365722d7265706c2d6c69623f6c6162656c3d636f6465636f76266c6f676f3d636f6465636f76267374796c653d666c61742d737175617265)](https://codecov.io/gh/ramsey/composer-repl-lib)

About
-----

[](#about)

This is the library that powers the [ramsey/composer-repl](https://github.com/ramsey/composer-repl)[Composer](https://getcomposer.org/) plugin. Since you can't extend Composer plugins, this exists to allow for extension. This library also allows for non-plugin use of the `repl` CLI tool, which you may use even if you do not wish to use the plugin functionality.

Tip

If you don't need to extend this for your own plugin needs, and you want the functionality provided by the plugin, check out [ramsey/composer-repl](https://github.com/ramsey/composer-repl) instead.

REPL stands for *read-eval-print loop*. It's a language shell that reads user input, evaluates the input using a programming language (in this case, PHP), and prints the output to the screen. Then, it returns to the read state (that's the *loop* part).

[PsySH](https://psysh.org) is the REPL providing the magic behind ramsey/composer-repl and ramsey/composer-repl-lib. PsySH is a language shell for PHP. It's similar to [irb](https://github.com/ruby/irb) for Ruby, [IPython](https://ipython.org) for Python, and [JShell](https://docs.oracle.com/javase/9/tools/jshell.htm) for Java. In addition to acting as a language shell, PsySH can also function as an interactive debugger and development console. [Laravel Tinker](https://github.com/laravel/tinker), [Drush](https://www.drush.org) for Drupal, [WP-CLI shell](https://github.com/wp-cli/shell-command) for WordPress, [CakePHP console](https://book.cakephp.org/3/en/console-and-shells/repl.html), and [Yii shell](https://github.com/yiisoft/yii2-shell) are a few of the projects using PsySH.

This project adheres to a [code of conduct](CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.

Installation
------------

[](#installation)

Install this package as a development dependency using [Composer](https://getcomposer.org).

```
composer require --dev ramsey/composer-repl-lib
```

Usage
-----

[](#usage)

Open your terminal and type `./vendor/bin/repl`.

You'll see something similar to this:

```
Psy Shell v0.12.20 (PHP 8.5.3 — cli) by Justin Hileman
------------------------------------------------------------------------
Welcome to the development console (REPL).
To learn more about what you can do in PsySH, type `help`.
------------------------------------------------------------------------
>>>

```

While in the dev console, you can do cool things like this:

```
> $hello = 'Hello, world'
= "Hello, world"

> echo $hello
Hello, world

> foreach ([1, 2, 3] as $x) echo $x . "\n"
1
2
3

> $date = new DateTimeImmutable();
= DateTimeImmutable @1772598406 {#359
    date: 2026-03-04 04:26:46.679771 UTC (+00:00),
  }

> $getDate = fn (DateTimeInterface $dt): DateTimeInterface => $dt;
= Closure(DateTimeInterface $dt): DateTimeInterface {#381 …3}

> t assertInstanceOf(DateTimeInterface::class, $date);
Test passed!

> t assertSame($date, $getDate($date))
Test passed!

> phpunit

PHPUnit 13.0.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.5.3
Configuration: /path/to/ramsey/composer-repl-lib/phpunit.xml.dist

..................................SS....                          40 / 40 (100%)

Time: 00:00.288, Memory: 48.00 MB

OK, but some tests were skipped!
Tests: 40, Assertions: 105, Skipped: 2.
```

Important

✨🐘 This implementation of PsySH has Super ElePHPant Powers. 🐘✨

Environment Bootstrapping
-------------------------

[](#environment-bootstrapping)

The power of this REPL comes in its ability to act as a tool in your local development environment. So, you might want to load parts of your environment (i.e., configuration, objects, etc.), so you can access these from within the REPL.

You can do this by specifying any number of PHP scripts to include in `composer.json`, like this:

```
{
    "extra": {
        "ramsey/composer-repl": {
            "includes": [
                "repl.php",
                "tests/bootstrap.php"
            ]
        }
    }
}
```

Any variables set or configuration loaded from these scripts is available to use from within the REPL.

For example, if `repl.php` contains:

```
