Skip to content

Commit

Permalink
Finish scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Silva committed Oct 21, 2014
2 parents cb314ee + 5ad9d2a commit 1a9d367
Show file tree
Hide file tree
Showing 47 changed files with 2,647 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
- memcached

before_script:
- sudo apt-get update > /dev/null
- sudo apt-get install -y --force-yes apache2 libapache2-mod-php5
- phpenv config-add custom.ini
- composer self-update
- composer install --prefer-source --no-interaction --dev
Expand Down
15 changes: 15 additions & 0 deletions src/Slick/Common/Inspector/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Slick\Common\Inspector;

use Slick\Utility\ArrayMethods;

/**
* Annotation
*
Expand Down Expand Up @@ -110,6 +112,19 @@ public function getParameters()
return $this->_parameters;
}

/**
* Returns the values as an array
*
* @return array
*/
public function allValues()
{
$raw = $this->_parameters['_raw'];
$values = explode(',', $raw);
$result = ArrayMethods::trim($values);
return $result;
}

/**
* Fix the parameters for string tags
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Slick/Form/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ public function getHtmlAttributes()

$parts = [];
foreach ($this->_attributes as $key => $value) {
if (is_numeric($key)) {
$parts[] = $value;
continue;
}
$parts[] = "{$key} = \"{$value}\"";
}
return implode(' ', $parts);
Expand Down
45 changes: 45 additions & 0 deletions src/Slick/Form/Element/SelectMultiple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* Select multiple
*
* @package Slick\Form\Element
* @author Filipe Silva <silvam.filipe@gmail.com>
* @copyright 2014 Filipe Silva
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @since Version 1.1.0
*/

namespace Slick\Form\Element;
use Slick\Form\Template\AbstractTemplate;

/**
* Select multiple
*
* @package Slick\Form\Element
* @author Filipe Silva <silvam.filipe@gmail.com>
*/
class SelectMultiple extends Select
{

/**
* @readwrite
* @var array HTML attributes
*/
protected $_attributes = [
'multiple'
];

/**
* lazy loads a default template for this element
*
* @return AbstractTemplate
*/
public function getTemplate()
{
if (is_null($this->_template)) {
$this->_template = new \Slick\Form\Template\SelectMultiple();
}
return $this->_template;
}
}
1 change: 1 addition & 0 deletions src/Slick/Form/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Factory extends Base
'select' => 'Slick\Form\Element\Select',
'area' => 'Slick\Form\Element\Area',
'checkbox' => 'Slick\Form\Element\Checkbox',
'selectMultiple' => 'Slick\Form\Element\SelectMultiple',
];

/**
Expand Down
29 changes: 29 additions & 0 deletions src/Slick/Form/Template/SelectMultiple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* SelectMultiple input
*
* @package Slick\Form\Template
* @author Filipe Silva <silvam.filipe@gmail.com>
* @copyright 2014 Filipe Silva
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @since Version 1.1.0
*/

namespace Slick\Form\Template;

/**
* SelectMultiple input
*
* @package Slick\Form\Template
* @author Filipe Silva <silvam.filipe@gmail.com>
*/
class SelectMultiple extends AbstractTemplate
{

/**
* @readwrite
* @var string
*/
protected $_templateFile = 'selectMultiple-input.html.twig';
}
13 changes: 13 additions & 0 deletions src/Slick/Form/Template/Views/selectMultiple-input.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "default-input.html.twig" %}

{% block inputElement %}
<select name="{{ element.getName }}[]" id="{{ element.getName() }}-input" {{ element.getHtmlAttributes|raw }}>
{% for key, value in element.getOptions() %}
{% if key == element.getValue() %}
<option selected="selected" value="{{ key }}">{{ value }}</option>
{% else %}
<option value="{{ key }}">{{ value }}</option>
{% endif %}
{% endfor %}
</select>
{% endblock %}
2 changes: 1 addition & 1 deletion src/Slick/Log/Handler/NullHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class NullHandler extends BaseHandler
*/
public function __construct($level = Logger::DEBUG)
{
parent::__construct($level, true);
parent::__construct($level, false);
}
}
22 changes: 11 additions & 11 deletions src/Slick/Log/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Log extends Base
* @read
* @var array A list of available loggers.
*/
protected $_loggers = array();
protected static $_loggers = array();

/**
* @read
Expand All @@ -49,9 +49,9 @@ class Log extends Base

/**
* Gets the logger for the channel with the provided name.
*
*
* @param string $name The loggers channel name to retrieve.
*
*
* @return \Monolog\Logger The logger object for the given channel name.
*/
public static function logger($name = null)
Expand All @@ -62,27 +62,27 @@ public static function logger($name = null)

/**
* Gets the logger for the channel with the provided name.
*
*
* @param string $name The loggers channel name to retrieve.
*
*
* @return \Monolog\Logger The logger object for the given channel name.
*/
public function getLogger($name = null)
{
$name = is_null($name) ? $this->defaultLogger : $name;
if (!isset($this->_loggers[$name])) {
$this->_loggers[$name] = new Logger($name);
$this->_setDefaultHandlers($this->_loggers[$name]);
if (!isset(static::$_loggers[$name])) {
static::$_loggers[$name] = new Logger($name);
$this->_setDefaultHandlers(static::$_loggers[$name]);
}
return $this->_loggers[$name];
return static::$_loggers[$name];
}

/**
* Adds the default log handlers to the provided logger.
*
*
* @param Logger $logger The logger object to add the handlers.
*/
protected function _setDefaultHandlers(Logger $logger)
protected function _setDefaultHandlers(Logger &$logger)
{
if (empty($this->_handlers)) {
$socketHandler = new NullHandler();
Expand Down
2 changes: 1 addition & 1 deletion src/Slick/Mvc/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* request dispatcher
* @method Application setLogger(LoggerInterface $logger) Sets a PSR-3 logger
*/
final class Application extends Base
class Application extends Base
{
/**
* @readwrite
Expand Down
127 changes: 127 additions & 0 deletions src/Slick/Mvc/Command/GenerateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

/**
* Generate controller command
*
* @package Slick\Mvc\Command
* @author Filipe Silva <silvam.filipe@gmail.com>
* @copyright 2014 Filipe Silva
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @since Version 1.0.0
*/

namespace Slick\Mvc\Command;

use Slick\Mvc\Command\Task\GenerateScaffoldController;
use Slick\Mvc\Command\Task\GenerateController as GenerateControllerTask;
use Slick\Mvc\Command\Utils\ControllerData;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Generate controller command
*
* @package Slick\Mvc\Command
* @author Filipe Silva <silvam.filipe@gmail.com>
*/
class GenerateController extends Command
{

/**
* Configures the current command.
*/
protected function configure()
{
$this
->setName("generate:controller")
->setDescription("Generate a controller file for the provided model name.")
->addArgument(
'modelName',
InputArgument::REQUIRED,
'Full qualified model class name'
)
->addOption(
'path',
'p',
InputOption::VALUE_OPTIONAL,
'Sets the application path where controllers are located',
getcwd()
)
->addOption(
'out',
'o',
InputOption::VALUE_OPTIONAL,
'The controllers folder where to save the controller.',
'Controllers'
)
->addOption(
'scaffold',
'S',
InputOption::VALUE_NONE,
'If set the controller will have only the scaffold property set.'
);
}

/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|integer null or 0 if everything went fine, or an error code
*
* @throws \LogicException When this abstract method is not implemented
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

/** @var Application $application */
$application = $this->getApplication();
$output->writeln($application->getLongVersion());
$output->writeln(
"Generate controller for model ". $input->getArgument('modelName')
);
$output->writeln("");

$controllerData = new ControllerData(
[
'controllerName' => $input->getArgument('modelName'),
'namespace' => $input->getOption('out'),
'modelName' => $input->getArgument('modelName')
]
);

$path = $input->getOption('path');
$path .= '/'. $input->getOption('out');

if ($input->getOption('scaffold')) {
$task = new GenerateScaffoldController(
[
'command' => $this,
'controllerData' => $controllerData,
'path' => $path
]
);
$task->run($input, $output);
} else {
$task = new GenerateControllerTask(
[
'command' => $this,
'controllerData' => $controllerData,
'path' => $path
]
);
$task->run($input, $output);
}
}
}

0 comments on commit 1a9d367

Please sign in to comment.