Repository: spatie/laravel-tinker-tools Branch: master Commit: 6cac407acd79 Files: 14 Total size: 13.5 KB Directory structure: gitextract_krs3r2ca/ ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .scrutinizer.yml ├── .styleci.yml ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src/ │ └── ShortClassNames.php └── tests/ ├── NamespacedClass.php └── ShortClassNamesTest.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ ; This file is for unifying the coding style for different editors and IDEs. ; More information at http://editorconfig.org root = true [*] charset = utf-8 indent_size = 4 indent_style = space end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false ================================================ FILE: .gitattributes ================================================ # Path-based git attributes # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /phpunit.xml.dist export-ignore /.scrutinizer.yml export-ignore /tests export-ignore /.editorconfig export-ignore ================================================ FILE: .gitignore ================================================ build composer.lock docs vendor ================================================ FILE: .scrutinizer.yml ================================================ filter: excluded_paths: [tests/*] checks: php: remove_extra_empty_lines: true remove_php_closing_tag: true remove_trailing_whitespace: true fix_use_statements: remove_unused: true preserve_multiple: false preserve_blanklines: true order_alphabetically: true fix_php_opening_tag: true fix_linefeed: true fix_line_ending: true fix_identation_4spaces: true fix_doc_comments: true ================================================ FILE: .styleci.yml ================================================ preset: laravel linting: true disabled: - single_class_element_per_statement ================================================ FILE: .travis.yml ================================================ language: php php: - 7.0 - 7.1 - 7.2 env: matrix: - COMPOSER_FLAGS="--prefer-lowest" - COMPOSER_FLAGS="" before_script: - travis_retry composer self-update - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source script: - composer dump-autoload -o - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover after_script: - php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover ================================================ FILE: CHANGELOG.md ================================================ # Changelog All notable changes to `laravel-tinker-tools` will be documented in this file ## 1.0.1 - 2017-07-28 - avoid aliasing interfaces ## 1.0.0 - 2017-05-22 - initial release ================================================ FILE: LICENSE.md ================================================ The MIT License (MIT) Copyright (c) Spatie bvba Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ **The functionality of this package is built into Laravel 5.5 and above, only install this in older Laravel versions** # Use short class names in an Artisan Tinker session [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-tinker-tools.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-tinker-tools) [![Build Status](https://img.shields.io/travis/spatie/laravel-tinker-tools/master.svg?style=flat-square)](https://travis-ci.org/spatie/laravel-tinker-tools) [![StyleCI](https://styleci.io/repos/91980495/shield?branch=master)](https://styleci.io/repos/91980495) [![Quality Score](https://img.shields.io/scrutinizer/g/spatie/laravel-tinker-tools.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/laravel-tinker-tools) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-tinker-tools.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-tinker-tools) When using Artisan's Tinker command it can be quite bothersome having to type the fully qualified classname to do something simple. ```php \App\Models\NewsItem::first(); ``` This package contains a class that, when fully installed lets you use the short class names: ```php NewsItem::first(); ``` ## Support us [](https://spatie.be/github-ad-click/laravel-tinker-tools) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation First install the package via Composer: ``` bash composer require spatie/laravel-tinker-tools ``` Next, create a file named `.psysh.php` in the root of your Laravel app with this content: ```php tests src/ ================================================ FILE: src/ShortClassNames.php ================================================ registerAutoloader(); } public function __construct(string $classMapPath) { $classFiles = include $classMapPath; $this->classes = collect($classFiles) ->map(function (string $path, string $fqcn) { $name = last(explode('\\', $fqcn)); return compact('fqcn', 'name'); }) ->filter() ->values(); } public function registerAutoloader() { spl_autoload_register([$this, 'aliasClass']); } public function aliasClass($findClass) { $class = $this->classes->first(function ($class) use ($findClass) { if ($class['name'] !== $findClass) { return false; } return ! (new ReflectionClass($class['fqcn']))->isInterface(); }); if (! $class) { return; } class_alias($class['fqcn'], $class['name']); } } ================================================ FILE: tests/NamespacedClass.php ================================================ assertFalse($foundClass); ShortClassNames::register(__DIR__.'/../vendor/composer/autoload_classmap.php'); $this->assertEquals('Oh, hi Mark', \NamespacedClass::getGreeting()); } }