2017 © Pedro Peláez
 

library injector

Copy / paste code at specific tokens in a list of PHP files

image

veewee/injector

Copy / paste code at specific tokens in a list of PHP files

  • Wednesday, March 21, 2018
  • by veewee
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

injector

Copy / paste code at specific locations in a list of files, (*2)

Installation

WIP: You can use the executable inside this repo for now ...., (*3)

$ 

Usage

Usage:
  copy-paste [options] [--] <src> <location>

Arguments:
  src                   The files you want to copy / paste in
  location              The location where you want to copy / paste

Options:
      --dry-run         Dont change the code but print the results to the screen
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Examples

echo " implements MyInterface" | ./bin/injector 'src/Testing' 'T_CLASS { <' --dry-run
echo "\nuse New\Imported\ClassName;" | ./bin/injector 'src/Testing' 'NEWUSE(New\\Imported\\Class)' --dry-run
echo "return 'Do something';\n        " | ./bin/injector 'src/Testing' 'METHODNAME(myFunction) { > >' --dry-run

Location operations

Every operation is split based on a space. For example.: T_CLASS { < contains out 3 tokens:, (*4)

  • T_CLASS: Will search for the next occurrence of the class keyword
  • {: Will search for the next occurrence of the brace with type {
  • <: Will select the previous token

These tokens will be detected in this orde., (*5)

Available location operations

Token lookups - T_*: Detect next token of PHP parser token constant. (Or the CT class in php-cs-fixer), (*6)

Brace lookups - {}[](): Detect next token of the selected brace type - ENDBLOCK(]})): Detect the end block of the selected brace type. - STARTBLOCK([{(): Detect the start block of the selected brace type., (*7)

Next / Previous lookups - <: Select previous token - >: Select next token - <<: Select Previous non-whitespace token - >>: Select Next non-whitespace token - <<<: Select Previous meaningful token (no whitespace, comment, docblocks, ...) - >>>: Select Next meaningful token (no whitespace, comment, docblocks, ...), (*8)

Macro lookups - METHODNAME(myFunction): Detect the function declaration of method myFunction - NEWUSE(MyNew\MyNamespace): Detect the best place to insert a new use statement MyNew\MyNamespace, (*9)

The Versions