PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/vendor/joomla/application/src/AbstractCliApplication.php

https://gitlab.com/vitaliylukin91/idea-rating
PHP | 108 lines | 34 code | 13 blank | 61 comment | 3 complexity | e8b51ad5e149d1a049eaf60971757353 MD5 | raw file
  1<?php
  2/**
  3 * Part of the Joomla Framework Application Package
  4 *
  5 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  6 * @license    GNU General Public License version 2 or later; see LICENSE
  7 */
  8
  9namespace Joomla\Application;
 10
 11use Joomla\Registry\Registry;
 12use Joomla\Input;
 13use Joomla\Application\Cli\CliOutput;
 14
 15/**
 16 * Base class for a Joomla! command line application.
 17 *
 18 * @since  1.0
 19 */
 20abstract class AbstractCliApplication extends AbstractApplication
 21{
 22	/**
 23	 * @var    CliOutput  Output object
 24	 * @since  1.0
 25	 */
 26	protected $output;
 27
 28	/**
 29	 * Class constructor.
 30	 *
 31	 * @param   Input\Cli  $input   An optional argument to provide dependency injection for the application's
 32	 *                              input object.  If the argument is a InputCli object that object will become
 33	 *                              the application's input object, otherwise a default input object is created.
 34	 * @param   Registry   $config  An optional argument to provide dependency injection for the application's
 35	 *                              config object.  If the argument is a Registry object that object will become
 36	 *                              the application's config object, otherwise a default config object is created.
 37	 *
 38	 * @param   CliOutput  $output  The output handler.
 39	 *
 40	 * @since   1.0
 41	 */
 42	public function __construct(Input\Cli $input = null, Registry $config = null, CliOutput $output = null)
 43	{
 44		// Close the application if we are not executed from the command line.
 45		// @codeCoverageIgnoreStart
 46		if (!defined('STDOUT') || !defined('STDIN') || !isset($_SERVER['argv']))
 47		{
 48			$this->close();
 49		}
 50
 51		// @codeCoverageIgnoreEnd
 52
 53		$this->output = ($output instanceof CliOutput) ? $output : new Cli\Output\Stdout;
 54
 55		// Call the constructor as late as possible (it runs `initialise`).
 56		parent::__construct($input instanceof Input\Input ? $input : new Input\Cli, $config);
 57
 58		// Set the execution datetime and timestamp;
 59		$this->set('execution.datetime', gmdate('Y-m-d H:i:s'));
 60		$this->set('execution.timestamp', time());
 61
 62		// Set the current directory.
 63		$this->set('cwd', getcwd());
 64	}
 65
 66	/**
 67	 * Get an output object.
 68	 *
 69	 * @return  CliOutput
 70	 *
 71	 * @since   1.0
 72	 */
 73	public function getOutput()
 74	{
 75		return $this->output;
 76	}
 77
 78	/**
 79	 * Write a string to standard output.
 80	 *
 81	 * @param   string   $text  The text to display.
 82	 * @param   boolean  $nl    True (default) to append a new line at the end of the output string.
 83	 *
 84	 * @return  AbstractCliApplication  Instance of $this to allow chaining.
 85	 *
 86	 * @codeCoverageIgnore
 87	 * @since   1.0
 88	 */
 89	public function out($text = '', $nl = true)
 90	{
 91		$this->output->out($text, $nl);
 92
 93		return $this;
 94	}
 95
 96	/**
 97	 * Get a value from standard input.
 98	 *
 99	 * @return  string  The input string from standard input.
100	 *
101	 * @codeCoverageIgnore
102	 * @since   1.0
103	 */
104	public function in()
105	{
106		return rtrim(fread(STDIN, 8192), "\n\r");
107	}
108}