Skip to content

[Proposal] Tinker Usability #2215

@johnnygreen

Description

@johnnygreen

Hello,

Using the Tinker command is sometimes frustrating. I find that making the below modifications makes its use more natural.

It would be nice to give an option for var_dump being the standard behavior, kind of like the ruby / rails REPL.

artisan tinker --dump
Illuminate/Foundation/Console/TinkerCommand.php
/**
 * Execute the console command.
 *
 * @return void
 */
public function fire()
{
  $input = $this->prompt();

  while ($input != 'quit')
  {
    try
    {
      if (starts_with($input, 'dump '))
      {
        $input = 'var_dump('.substr($input, 5).');';
      } 
      else if ($this->input->getOption('dump'))
      {
        $input = 'var_dump('.$input.');';
      }

      eval($input);
    }
    catch (\Exception $e)
    {
      $this->error($e->getMessage());
    }

    $input = $this->prompt();
  }
}

/**
 * Get the console command options.
 *
 * @return array
 */
protected function getOptions()
{
  return array(
    array('dump', 'd', InputOption::VALUE_NONE, 'Dump the contents of each input by default', false)
  );
}

Also, I propose modification of the Tinker command to allow for a 'clear' command. This would clear the screen like 'clear' in bash or 'cls' on windows.

Illuminate/Foundation/Console/TinkerCommand.php
/**
 * Execute the console command.
 *
 * @return void
 */
public function fire()
{
  $input = $this->prompt();

  while ($input != 'quit')
  {
    if ($input == 'clear' or $input == 'cls')
    {
      passthru($input);
      $input = $this->prompt();
      continue;
    }

    try
    {
      if (starts_with($input, 'dump '))
      {
        $input = 'var_dump('.substr($input, 5).');';
      }

      eval($input);
    }
    catch (\Exception $e)
    {
      $this->error($e->getMessage());
    }

    $input = $this->prompt();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions