Full Code of yiisoft/yii2-shell for AI

master 747678498438 cached
15 files
11.2 KB
3.2k tokens
8 symbols
1 requests
Download .txt
Repository: yiisoft/yii2-shell
Branch: master
Commit: 747678498438
Files: 15
Total size: 11.2 KB

Directory structure:
gitextract_r687wq14/

├── .editorconfig
├── .gitattributes
├── .github/
│   ├── CONTRIBUTING.md
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE.md
│   ├── PULL_REQUEST_TEMPLATE.md
│   └── SECURITY.md
├── .gitignore
├── Bootstrap.php
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── ShellController.php
├── YiiCaster.php
└── composer.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .editorconfig
================================================
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false


================================================
FILE: .gitattributes
================================================
# Ignore all test and documentation for archive
/.gitattributes     export-ignore
/.gitignore         export-ignore
/.scrutinizer.yml   export-ignore
/.travis.yml        export-ignore
/phpunit.xml.dist   export-ignore
/tests              export-ignore
/docs               export-ignore


================================================
FILE: .github/CONTRIBUTING.md
================================================
Contributing to Yii2
====================

- [Report an issue](https://github.com/yiisoft/yii2/blob/master/docs/internals/report-an-issue.md)
- [Translate documentation or messages](https://github.com/yiisoft/yii2/blob/master/docs/internals/translation-workflow.md)
- [Give us feedback or start a design discussion](https://forum.yiiframework.com/c/yii-2-0/general-discussions/16)
- [Contribute to the core code or fix bugs](https://github.com/yiisoft/yii2/blob/master/docs/internals/git-workflow.md)


================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms

open_collective: yiisoft


================================================
FILE: .github/ISSUE_TEMPLATE.md
================================================
<!--
Please use this issue tracker for bugs and feature requests only. In case you need support please use one of
Yii communities listed at https://github.com/yiisoft/yii2/wiki/communities
-->

### What steps will reproduce the problem?

### What's expected?

### What do you get instead?


### Additional info

| Q                | A
| ---------------- | ---
| Yii vesion       |
| PHP version      |
| Operating system |


================================================
FILE: .github/PULL_REQUEST_TEMPLATE.md
================================================
| Q             | A
| ------------- | ---
| Is bugfix?    | ✔️/❌
| New feature?  | ✔️/❌
| Breaks BC?    | ✔️/❌
| Fixed issues  | <!-- comma-separated list of tickets # fixed by the PR, if any -->


================================================
FILE: .github/SECURITY.md
================================================
# Security Policy

Please use the [security issue form](https://www.yiiframework.com/security) to report to us any security issue you find in Yii.
DO NOT use the issue tracker or discuss it in the public forum as it will cause more damage than help.

Please note that as a non-commercial OpenSource project we are not able to pay bounties at the moment.


================================================
FILE: .gitignore
================================================
# phpstorm project files
.idea

# netbeans project files
nbproject

# zend studio for eclipse project files
.buildpath
.project
.settings

# windows thumbnail cache
Thumbs.db

# composer
composer.phar
/vendor
/composer.lock

# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar
# local phpunit config
/phpunit.xmls


================================================
FILE: Bootstrap.php
================================================
<?php
/**
 * @link https://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license https://www.yiiframework.com/license/
 */

namespace yii\shell;

use yii\base\BootstrapInterface;
use yii\helpers\ArrayHelper;

/**
 * Class Bootstrap
 *
 * @author Sascha Vincent Kurowski <svkurowski@gmail.com>
 * @since 2.0
 */
class Bootstrap implements BootstrapInterface
{
    /**
     * @inheritdoc
     */
    public function bootstrap($app)
    {
        if ($app instanceof \yii\console\Application) {
            $app->controllerMap['shell'] = ArrayHelper::merge([
                'class' => 'yii\shell\ShellController',
                'shellConfig' => [
                    'updateCheck' => 'never',
                ],
            ], isset($app->controllerMap['shell']) ? $app->controllerMap['shell'] : []);
        }
    }
}


================================================
FILE: CHANGELOG.md
================================================
Yii Framework 2 Shell extension Change Log
==========================================

2.0.7 under development
-----------------------

- Chg #43: Version bump for symfony/var-dumper dependency (Jiminald)


2.0.6 February 13, 2025
-----------------------

- Enh #32: Disable update check, allow configuring PsySH (flaviovs)
- Enh #40: Allow psy/psysh ^0.12.0 additionally (JasonStainton)


2.0.5 September 04, 2022
------------------------

- Enh #28: Allow psy/psysh ^0.11.0 additionally (wa1kb0y)


2.0.4 May 02, 2020
------------------

- Enh #27: Allow psy/psysh ~0.10.3 additionally to ~0.9.3 (tobiase)


2.0.3 March 03, 2020
--------------------

- Enh #26: Add compatibility with `symfony/var-dumper` 5.x (samdark)


2.0.2 January 07, 2019
----------------------

- Enh #19: Bump psy/psysh to ~0.9.3 (ricpelo)


2.0.1 March 26, 2018
--------------------

- Enh #10, #13: Updated psy version (kyle-mccarthy, samdark)


2.0.0 November 22, 2016
-----------------------

- Initial release.



================================================
FILE: LICENSE.md
================================================
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

 * Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.
 * Neither the name of Yii Software LLC nor the names of its
   contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.


================================================
FILE: README.md
================================================
<p align="center">
    <a href="https://github.com/yiisoft" target="_blank">
        <img src="https://avatars0.githubusercontent.com/u/993323" height="100px">
    </a>
    <h1 align="center">Interactive Shell Extension for Yii 2</h1>
    <br>
</p>

This extension provides an interactive shell for [Yii framework 2.0](https://www.yiiframework.com) based on [psysh](https://psysh.org/).

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-shell/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-shell)
[![Total Downloads](https://poser.pugx.org/yiisoft/yii2-shell/downloads.png)](https://packagist.org/packages/yiisoft/yii2-shell)


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

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

Either run

    composer require yiisoft/yii2-shell

or add

```json
"yiisoft/yii2-shell": "~2.0.0"
```

to the `require` section of your composer.json.


Usage
-----

After installation, you will be able to run the interactive shell via command line:

```
# Change path to your application's root directory
cd path/to/myapp

# Start the interactive shell
./yii shell
```

You can access the application object using `Yii::$app`. Additionally you have access to all your and your dependencies' classes.

See [psysh's website](https://psysh.org/#features) for a list of available features.


Configuration
-------------

You can configure the PsySH shell by setting options via the `shellConfig` variable in the controller, i.e. add this to your console application configuration:


```
'controllerMap' => [
    'shell' => [
        'shellConfig' => [
            'updateCheck' => 'weekly',
            'verbosity' => \Psy\Configuration::VERBOSITY_VERBOSE,
        ],
    ],
],
```

See https://github.com/bobthecow/psysh/wiki/Config-options for a list of PsySH configurable options.

**Note**: `updateCheck` is explictly set to _never_ by yii2-shell. All other PsySH options use default values.


Screenshot
----------

The following screenshot shows a usage example:

![Usage example of Yii2 shell](screenshot.png)


================================================
FILE: ShellController.php
================================================
<?php
/**
 * @link https://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license https://www.yiiframework.com/license/
 */

namespace yii\shell;

use yii\console\Controller;
use Psy\Shell;
use Psy\Configuration;

/**
 * Runs interactive shell. That is especially useful when developing an application and you want to try
 * some method of your code.
 *
 * @author Daniel Gomez Pan <pana_1990@hotmail.com>
 * @since 2.0
 */
class ShellController extends Controller
{
    /**
     * @var array include file(s) before starting tinker shell
     */
    public $include = [];
    /**
     * @var array PsySH shell configuration array
     * @since 2.0.6
     */
    public $shellConfig = [];


    /**
     * @inheritdoc
     */
    public function options($actionID)
    {
        return array_merge(parent::options($actionID), [
            'include'
        ]);
    }

    /**
     * Runs interactive shell
     */
    public function actionIndex()
    {
        $config = new Configuration;
        $config->loadConfig($this->shellConfig);
        $config->getPresenter()->addCasters(
            $this->getCasters()
        );
        $shell = new Shell($config);
        $shell->setIncludes($this->include);
        $shell->run();
    }

    /**
     * @return array casters for psysh
     */
    protected function getCasters()
    {
        return [
            'yii\db\ActiveRecord' => 'yii\shell\YiiCaster::castModel',
        ];
    }
}


================================================
FILE: YiiCaster.php
================================================
<?php
/**
 * @link https://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license https://www.yiiframework.com/license/
 */

namespace yii\shell;

use Symfony\Component\VarDumper\Caster\Caster;
use yii\db\ActiveRecord;

/**
 * YiiCaster provides wrapper for casters of psysh
 *
 * @author Daniel Gomez Pan <pana_1990@hotmail.com>
 * @since 2.0
 */
class YiiCaster
{
    /**
     * Get an array representing the properties of a model.
     *
     * @param \yii\db\ActiveRecord $model
     * @return array
     */
    public static function castModel(ActiveRecord $model)
    {
        $attributes = array_merge(
            $model->getAttributes(), $model->getRelatedRecords()
        );
        $results = [];
        foreach ($attributes as $key => $value) {
            $results[Caster::PREFIX_VIRTUAL.$key] = $value;
        }
        return $results;
    }
}


================================================
FILE: composer.json
================================================
{
    "name": "yiisoft/yii2-shell",
    "description": "The interactive shell extension for Yii framework",
    "keywords": [
        "yii2",
        "shell"
    ],
    "type": "yii2-extension",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/yiisoft/yii2-shell/issues",
        "forum": "https://www.yiiframework.com/forum/",
        "wiki": "https://www.yiiframework.com/wiki/",
        "irc": "ircs://irc.libera.chat:6697/yii",
        "source": "https://github.com/yiisoft/yii2-shell"
    },
    "authors": [
        {
            "name": "Daniel Gomez Pan",
            "email": "pana_1990@hotmail.com"
        },
        {
            "name": "Sascha Vincent Kurowski",
            "email": "svkurowski@gmail.com"
        }
    ],
    "require": {
        "yiisoft/yii2": "~2.0.0",
        "psy/psysh": "~0.9.3|~0.10.3|^0.11.0|^0.12.0",
        "symfony/var-dumper": "~2.7|~3.0|~4.0|~5.0|~6.0|~7.0"
    },
    "autoload": {
        "psr-4": {
            "yii\\shell\\": ""
        }
    },
    "extra": {
        "bootstrap": "yii\\shell\\Bootstrap",
        "branch-alias": {
            "dev-master": "2.0.x-dev"
        }
    }
}
Download .txt
gitextract_r687wq14/

├── .editorconfig
├── .gitattributes
├── .github/
│   ├── CONTRIBUTING.md
│   ├── FUNDING.yml
│   ├── ISSUE_TEMPLATE.md
│   ├── PULL_REQUEST_TEMPLATE.md
│   └── SECURITY.md
├── .gitignore
├── Bootstrap.php
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── ShellController.php
├── YiiCaster.php
└── composer.json
Download .txt
SYMBOL INDEX (8 symbols across 3 files)

FILE: Bootstrap.php
  class Bootstrap (line 19) | class Bootstrap implements BootstrapInterface
    method bootstrap (line 24) | public function bootstrap($app)

FILE: ShellController.php
  class ShellController (line 21) | class ShellController extends Controller
    method options (line 37) | public function options($actionID)
    method actionIndex (line 47) | public function actionIndex()
    method getCasters (line 62) | protected function getCasters()

FILE: YiiCaster.php
  class YiiCaster (line 19) | class YiiCaster
    method castModel (line 27) | public static function castModel(ActiveRecord $model)
Condensed preview — 15 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (13K chars).
[
  {
    "path": ".editorconfig",
    "chars": 208,
    "preview": "# editorconfig.org\n\nroot = true\n\n[*]\ncharset = utf-8\nend_of_line = lf\ninsert_final_newline = true\nindent_style = space\ni"
  },
  {
    "path": ".gitattributes",
    "chars": 286,
    "preview": "# Ignore all test and documentation for archive\n/.gitattributes     export-ignore\n/.gitignore         export-ignore\n/.sc"
  },
  {
    "path": ".github/CONTRIBUTING.md",
    "chars": 501,
    "preview": "Contributing to Yii2\n====================\n\n- [Report an issue](https://github.com/yiisoft/yii2/blob/master/docs/internal"
  },
  {
    "path": ".github/FUNDING.yml",
    "chars": 72,
    "preview": "# These are supported funding model platforms\n\nopen_collective: yiisoft\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE.md",
    "chars": 423,
    "preview": "<!--\nPlease use this issue tracker for bugs and feature requests only. In case you need support please use one of\nYii co"
  },
  {
    "path": ".github/PULL_REQUEST_TEMPLATE.md",
    "chars": 196,
    "preview": "| Q             | A\n| ------------- | ---\n| Is bugfix?    | ✔️/❌\n| New feature?  | ✔️/❌\n| Breaks BC?    | ✔️/❌\n| Fixed i"
  },
  {
    "path": ".github/SECURITY.md",
    "chars": 354,
    "preview": "# Security Policy\n\nPlease use the [security issue form](https://www.yiiframework.com/security) to report to us any secur"
  },
  {
    "path": ".gitignore",
    "chars": 338,
    "preview": "# phpstorm project files\n.idea\n\n# netbeans project files\nnbproject\n\n# zend studio for eclipse project files\n.buildpath\n."
  },
  {
    "path": "Bootstrap.php",
    "chars": 849,
    "preview": "<?php\n/**\n * @link https://www.yiiframework.com/\n * @copyright Copyright (c) 2008 Yii Software LLC\n * @license https://w"
  },
  {
    "path": "CHANGELOG.md",
    "chars": 994,
    "preview": "Yii Framework 2 Shell extension Change Log\n==========================================\n\n2.0.7 under development\n---------"
  },
  {
    "path": "LICENSE.md",
    "chars": 1523,
    "preview": "Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)\nAll rights reserved.\n\nRedistribution and use in source and"
  },
  {
    "path": "README.md",
    "chars": 2162,
    "preview": "<p align=\"center\">\n    <a href=\"https://github.com/yiisoft\" target=\"_blank\">\n        <img src=\"https://avatars0.githubus"
  },
  {
    "path": "ShellController.php",
    "chars": 1473,
    "preview": "<?php\n/**\n * @link https://www.yiiframework.com/\n * @copyright Copyright (c) 2008 Yii Software LLC\n * @license https://w"
  },
  {
    "path": "YiiCaster.php",
    "chars": 892,
    "preview": "<?php\n/**\n * @link https://www.yiiframework.com/\n * @copyright Copyright (c) 2008 Yii Software LLC\n * @license https://w"
  },
  {
    "path": "composer.json",
    "chars": 1178,
    "preview": "{\n    \"name\": \"yiisoft/yii2-shell\",\n    \"description\": \"The interactive shell extension for Yii framework\",\n    \"keyword"
  }
]

About this extraction

This page contains the full source code of the yiisoft/yii2-shell GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 15 files (11.2 KB), approximately 3.2k tokens, and a symbol index with 8 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!