Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Rename MuseController
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Jul 3, 2016
1 parent fea38b1 commit eb6c14d
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 2 deletions.
89 changes: 89 additions & 0 deletions src/Muse/Controller/AbstractMuseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Part of muse project.
*
* @copyright Copyright (C) 2011 - 2015 SMS Taiwan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Muse\Controller;

use Muse\IO\IOInterface;
use Windwalker\Structure\Structure;

/**
* Base controller class.
*/
abstract class AbstractMuseController implements MuseControllerInterface
{
/**
* IO adapter.
*
* @var IOInterface
*/
public $io;

/**
* Instantiate the controller.
*
* @param IOInterface $io The Controller object.
* @param Structure $config Config
*/
public function __construct(IOInterface $io, Structure $config = null)
{
$this->io = $io;
$this->config = $config ? : new Structure;
}

/**
* Write a string to standard output.
*
* @param string $text The text to display.
*
* @return AbstractMuseController Instance of $this to allow chaining.
*/
public function out($text = '')
{
$this->io->out($text);

return $this;
}

/**
* Write a string to standard error output.
*
* @param string $text The text to display.
*
* @return AbstractMuseController Instance of $this to allow chaining.
*/
public function err($text = '')
{
$this->io->err($text);

return $this;
}

/**
* Get a value from standard input.
*
* @param string $question The question you want to ask user.
*
* @return string The input string from standard input.
*/
public function in($question = '')
{
return $this->io->in($question);
}

/**
* Close system.
*
* @param string $text Close message.
*
* @return void
*/
public function close($text = '')
{
$this->io->close($text);
}
}
2 changes: 1 addition & 1 deletion src/Muse/Controller/AbstractTaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Base controller of task.
*/
abstract class AbstractTaskController extends AbstractController
abstract class AbstractTaskController extends AbstractMuseController
{
/**
* Property config.
Expand Down
2 changes: 1 addition & 1 deletion src/Muse/Controller/GeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Main entry of Code Generator.
*/
class GeneratorController extends AbstractController
class GeneratorController extends AbstractMuseController
{
/**
* Task name.
Expand Down
63 changes: 63 additions & 0 deletions src/Muse/Controller/MuseControllerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Part of muse project.
*
* @copyright Copyright (C) 2011 - 2015 SMS Taiwan, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Muse\Controller;

/**
* Interface ControllerInterface
*/
interface MuseControllerInterface
{
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute();

/**
* Write a string to standard output.
*
* @param string $text The text to display.
*
* @return MuseControllerInterface Instance of $this to allow chaining.
*/
public function out($text = '');

/**
* Write a string to standard error output.
*
* @param string $text The text to display.
*
* @return MuseControllerInterface Instance of $this to allow chaining.
*/
public function err($text = '');

/**
* Get a value from standard input.
*
* @param string $question The question you want to ask user.
*
* @return string The input string from standard input.
*/
public function in($question = '');

/**
* Close system.
*
* @param string $text Close message.
*
* @return void
*/
public function close($text = '');
}

0 comments on commit eb6c14d

Please sign in to comment.