Skip to content

Commit

Permalink
made some method name changes to have a better coherence throughout t…
Browse files Browse the repository at this point in the history
…he framework

When an object has a "main" many relation with related "things" (objects,
parameters, ...), the method names are normalized:

 * get()
 * set()
 * all()
 * replace()
 * remove()
 * clear()
 * isEmpty()
 * add()
 * register()
 * count()
 * keys()

The classes below follow this method naming convention:

 * BrowserKit\CookieJar -> Cookie
 * BrowserKit\History -> Request
 * Console\Application -> Command
 * Console\Application\Helper\HelperSet -> HelperInterface
 * DependencyInjection\Container -> services
 * DependencyInjection\ContainerBuilder -> services
 * DependencyInjection\ParameterBag\ParameterBag -> parameters
 * DependencyInjection\ParameterBag\FrozenParameterBag -> parameters
 * DomCrawler\Form -> FormField
 * EventDispatcher\Event -> parameters
 * Form\FieldGroup -> Field
 * HttpFoundation\HeaderBag -> headers
 * HttpFoundation\ParameterBag -> parameters
 * HttpFoundation\Session -> attributes
 * HttpKernel\Profiler\Profiler -> DataCollectorInterface
 * Routing\RouteCollection -> Route
 * Security\Authentication\AuthenticationProviderManager -> AuthenticationProviderInterface
 * Templating\Engine -> HelperInterface
 * Translation\MessageCatalogue -> messages

The usage of these methods are only allowed when it is clear that there is a
main relation:

 * a CookieJar has many Cookies;

 * a Container has many services and many parameters (as services is the main
   relation, we use the naming convention for this relation);

 * a Console Input has many arguments and many options. There is no "main"
   relation, and so the naming convention does not apply.

For many relations where the convention does not apply, the following methods
must be used instead (where XXX is the name of the related thing):

 * get()      -> getXXX()
 * set()      -> setXXX()
 * all()      -> getXXXs()
 * replace()  -> setXXXs()
 * remove()   -> removeXXX()
 * clear()    -> clearXXX()
 * isEmpty()  -> isEmptyXXX()
 * add()      -> addXXX()
 * register() -> registerXXX()
 * count()    -> countXXX()
 * keys()
  • Loading branch information
fabpot committed Nov 25, 2010
1 parent 5c5e8f1 commit 944d91c
Show file tree
Hide file tree
Showing 56 changed files with 266 additions and 266 deletions.
Expand Up @@ -34,8 +34,8 @@ public function indexAction($path, $controller)
$request = $this->container->get('request');
$attributes = $request->attributes;

$attributes->delete('path');
$attributes->delete('controller');
$attributes->remove('path');
$attributes->remove('controller');
if ('none' !== $path)
{
parse_str($path, $tmp);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/RequestListener.php
Expand Up @@ -49,8 +49,8 @@ public function register(EventDispatcher $dispatcher, $priority = 0)

public function handle(Event $event)
{
$request = $event->getParameter('request');
$master = HttpKernelInterface::MASTER_REQUEST === $event->getParameter('request_type');
$request = $event->get('request');
$master = HttpKernelInterface::MASTER_REQUEST === $event->get('request_type');

$this->initializeSession($request, $master);

Expand Down
Expand Up @@ -47,7 +47,7 @@ public function register(EventDispatcher $dispatcher, $priority = 0)

public function handle(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
return $response;
}

Expand All @@ -57,10 +57,10 @@ public function handle(Event $event, Response $response)
$response->headers->get('location'), $response->headers->get('location'))
);
$response->setStatusCode(200);
$response->headers->delete('Location');
$response->headers->remove('Location');
}

$request = $event->getParameter('request');
$request = $event->get('request');
if (!$response->headers->has('X-Debug-Token')
|| '3' === substr($response->getStatusCode(), 0, 1)
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
Expand Down
34 changes: 17 additions & 17 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -37,7 +37,7 @@
* Usage:
*
* $app = new Application('myapp', '1.0 (stable)');
* $app->addCommand(new SimpleCommand());
* $app->add(new SimpleCommand());
* $app->run();
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
Expand Down Expand Up @@ -74,8 +74,8 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
new DialogHelper(),
));

$this->addCommand(new HelpCommand());
$this->addCommand(new ListCommand());
$this->add(new HelpCommand());
$this->add(new ListCommand());

$this->definition = new InputDefinition(array(
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
Expand Down Expand Up @@ -181,7 +181,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
}

// the command name MUST be the first element of the input
$command = $this->findCommand($name);
$command = $this->find($name);

$this->runningCommand = $command;
$statusCode = $command->run($input, $output);
Expand Down Expand Up @@ -329,7 +329,7 @@ public function getLongVersion()
*/
public function register($name)
{
return $this->addCommand(new Command($name));
return $this->add(new Command($name));
}

/**
Expand All @@ -340,7 +340,7 @@ public function register($name)
public function addCommands(array $commands)
{
foreach ($commands as $command) {
$this->addCommand($command);
$this->add($command);
}
}

Expand All @@ -353,7 +353,7 @@ public function addCommands(array $commands)
*
* @return Command The registered command
*/
public function addCommand(Command $command)
public function add(Command $command)
{
$command->setApplication($this);

Expand All @@ -375,7 +375,7 @@ public function addCommand(Command $command)
*
* @throws \InvalidArgumentException When command name given does not exist
*/
public function getCommand($name)
public function get($name)
{
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
Expand All @@ -386,7 +386,7 @@ public function getCommand($name)
if ($this->wantHelps) {
$this->wantHelps = false;

$helpCommand = $this->getCommand('help');
$helpCommand = $this->get('help');
$helpCommand->setCommand($command);

return $helpCommand;
Expand All @@ -402,7 +402,7 @@ public function getCommand($name)
*
* @return Boolean true if the command exists, false otherwise
*/
public function hasCommand($name)
public function has($name)
{
return isset($this->commands[$name]) || isset($this->aliases[$name]);
}
Expand Down Expand Up @@ -451,7 +451,7 @@ public function findNamespace($namespace)
/**
* Finds a command by name or alias.
*
* Contrary to getCommand, this command tries to find the best
* Contrary to get, this command tries to find the best
* match if you give it an abbreviation of a name or alias.
*
* @param string $name A command name or a command alias
Expand All @@ -460,7 +460,7 @@ public function findNamespace($namespace)
*
* @throws \InvalidArgumentException When command name is incorrect or ambiguous
*/
public function findCommand($name)
public function find($name)
{
// namespace
$namespace = '';
Expand All @@ -481,7 +481,7 @@ public function findCommand($name)

$abbrevs = static::getAbbreviations($commands);
if (isset($abbrevs[$name]) && 1 == count($abbrevs[$name])) {
return $this->getCommand($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
return $this->get($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
}

if (isset($abbrevs[$name]) && count($abbrevs[$name]) > 1) {
Expand All @@ -500,7 +500,7 @@ public function findCommand($name)
throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $fullName, $this->getAbbreviationSuggestions($abbrevs[$fullName])));
}

return $this->getCommand($abbrevs[$fullName][0]);
return $this->get($abbrevs[$fullName][0]);
}

/**
Expand All @@ -512,7 +512,7 @@ public function findCommand($name)
*
* @return array An array of Command instances
*/
public function getCommands($namespace = null)
public function all($namespace = null)
{
if (null === $namespace) {
return $this->commands;
Expand Down Expand Up @@ -566,7 +566,7 @@ static public function getAbbreviations($names)
*/
public function asText($namespace = null)
{
$commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;

$messages = array($this->getHelp(), '');
if ($namespace) {
Expand Down Expand Up @@ -607,7 +607,7 @@ public function asText($namespace = null)
*/
public function asXml($namespace = null, $asDom = false)
{
$commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;

$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Command/HelpCommand.php
Expand Up @@ -65,7 +65,7 @@ public function setCommand(Command $command)
protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->command) {
$this->command = $this->application->getCommand($input->getArgument('command_name'));
$this->command = $this->application->get($input->getArgument('command_name'));
}

if ($input->getOption('xml')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Shell.php
Expand Up @@ -97,7 +97,7 @@ protected function autocompleter($text, $position)

// task name?
if (false === strpos($text, ' ') || !$text) {
return array_keys($this->application->getCommands());
return array_keys($this->application->all());
}

// options and arguments?
Expand Down
32 changes: 16 additions & 16 deletions src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -215,7 +215,7 @@ public function getMethod()
*
* @return Boolean true if the field exists, false otherwise
*/
public function hasField($name)
public function has($name)
{
return isset($this->fields[$name]);
}
Expand All @@ -229,9 +229,9 @@ public function hasField($name)
*
* @throws \InvalidArgumentException When field is not present in this form
*/
public function getField($name)
public function get($name)
{
if (!$this->hasField($name)) {
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('The form has no "%s" field', $name));
}

Expand All @@ -245,7 +245,7 @@ public function getField($name)
*
* @return FormField The field instance
*/
public function setField(Field\FormField $field)
public function set(Field\FormField $field)
{
$this->fields[$field->getName()] = $field;
}
Expand All @@ -255,7 +255,7 @@ public function setField(Field\FormField $field)
*
* @return array An array of fields
*/
public function getFields()
public function all()
{
return $this->fields;
}
Expand All @@ -280,21 +280,21 @@ protected function initialize()
$nodeName = $node->nodeName;

if ($node === $button) {
$this->setField(new Field\InputFormField($node));
$this->set(new Field\InputFormField($node));
} elseif ('select' == $nodeName || 'input' == $nodeName && 'checkbox' == $node->getAttribute('type')) {
$this->setField(new Field\ChoiceFormField($node));
$this->set(new Field\ChoiceFormField($node));
} elseif ('input' == $nodeName && 'radio' == $node->getAttribute('type')) {
if ($this->hasField($node->getAttribute('name'))) {
$this->getField($node->getAttribute('name'))->addChoice($node);
if ($this->has($node->getAttribute('name'))) {
$this->get($node->getAttribute('name'))->addChoice($node);
} else {
$this->setField(new Field\ChoiceFormField($node));
$this->set(new Field\ChoiceFormField($node));
}
} elseif ('input' == $nodeName && 'file' == $node->getAttribute('type')) {
$this->setField(new Field\FileFormField($node));
$this->set(new Field\FileFormField($node));
} elseif ('input' == $nodeName && !in_array($node->getAttribute('type'), array('submit', 'button', 'image'))) {
$this->setField(new Field\InputFormField($node));
$this->set(new Field\InputFormField($node));
} elseif ('textarea' == $nodeName) {
$this->setField(new Field\TextareaFormField($node));
$this->set(new Field\TextareaFormField($node));
}
}
}
Expand All @@ -308,7 +308,7 @@ protected function initialize()
*/
public function offsetExists($name)
{
return $this->hasField($name);
return $this->has($name);
}

/**
Expand All @@ -322,7 +322,7 @@ public function offsetExists($name)
*/
public function offsetGet($name)
{
if (!$this->hasField($name)) {
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name));
}

Expand All @@ -339,7 +339,7 @@ public function offsetGet($name)
*/
public function offsetSet($name, $value)
{
if (!$this->hasField($name)) {
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('The form field "%s" does not exist', $name));
}

Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/EventDispatcher/Event.php
Expand Up @@ -102,7 +102,7 @@ public function isProcessed()
*
* @return array The event parameters
*/
public function getParameters()
public function all()
{
return $this->parameters;
}
Expand All @@ -114,7 +114,7 @@ public function getParameters()
*
* @return Boolean true if the parameter exists, false otherwise
*/
public function hasParameter($name)
public function has($name)
{
return array_key_exists($name, $this->parameters);
}
Expand All @@ -128,7 +128,7 @@ public function hasParameter($name)
*
* @throws \InvalidArgumentException When parameter doesn't exists for this event
*/
public function getParameter($name)
public function get($name)
{
if (!array_key_exists($name, $this->parameters)) {
throw new \InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
Expand All @@ -143,7 +143,7 @@ public function getParameter($name)
* @param string $name The parameter name
* @param mixed $value The parameter value
*/
public function setParameter($name, $value)
public function set($name, $value)
{
$this->parameters[$name] = $value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/HeaderBag.php
Expand Up @@ -145,11 +145,11 @@ public function contains($key, $value)
}

/**
* Deletes a header.
* Removes a header.
*
* @param string $key The HTTP header name
*/
public function delete($key)
public function remove($key)
{
$key = strtr(strtolower($key), '_', '-');

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/ParameterBag.php
Expand Up @@ -105,11 +105,11 @@ public function has($key)
}

/**
* Deletes a parameter.
* Removes a parameter.
*
* @param string $key The key
*/
public function delete($key)
public function remove($key)
{
unset($this->parameters[$key]);
}
Expand Down

0 comments on commit 944d91c

Please sign in to comment.