8000 made some method name changes to have a better coherence throughout t… · symfony/symfony@944d91c · GitHub
[go: up one dir, main page]

Skip to content

Commit 944d91c

Browse files
committed
made some method name changes to have a better coherence throughout the 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\MessageC 8000 atalogue -> 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()
1 parent 5c5e8f1 commit 944d91c

File tree

56 files changed

+266
-266
lines changed
  • Routing
  • Security/Authentication
  • Translation
  • tests/Symfony/Tests/Component
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    56 files changed

    +266
    -266
    lines changed

    src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -34,8 +34,8 @@ public function indexAction($path, $controller)
    3434
    $request = $this->container->get('request');
    3535
    $attributes = $request->attributes;
    3636

    37-
    $attributes->delete('path');
    38-
    $attributes->delete('controller');
    37+
    $attributes->remove('path');
    38+
    $attributes->remove('controller');
    3939
    if ('none' !== $path)
    4040
    {
    4141
    parse_str($path, $tmp);

    src/Symfony/Bundle/FrameworkBundle/RequestListener.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -49,8 +49,8 @@ public function register(EventDispatcher $dispatcher, $priority = 0)
    4949

    5050
    public function handle(Event $event)
    5151
    {
    52-
    $request = $event->getParameter('request');
    53-
    $master = HttpKernelInterface::MASTER_REQUEST === $event->getParameter('request_type');
    52+
    $request = $event->get('request');
    53+
    $master = HttpKernelInterface::MASTER_REQUEST === $event->get('request_type');
    5454

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

    src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -47,7 +47,7 @@ public function register(EventDispatcher $dispatcher, $priority = 0)
    4747

    4848
    public function handle(Event $event, Response $response)
    4949
    {
    50-
    if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
    50+
    if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
    5151
    return $response;
    5252
    }
    5353

    @@ -57,10 +57,10 @@ public function handle(Event $event, Response $response)
    5757
    $response->headers->get('location'), $response->headers->get('location'))
    5858
    );
    5959
    $response->setStatusCode(200);
    60-
    $response->headers->delete('Location');
    60+
    $response->headers->remove('Location');
    6161
    }
    6262

    63-
    $request = $event->getParameter('request');
    63+
    $request = $event->get('request');
    6464
    if (!$response->headers->has('X-Debug-Token')
    6565
    || '3' === substr($response->getStatusCode(), 0, 1)
    6666
    || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))

    src/Symfony/Component/Console/Application.php

    Lines changed: 17 additions & 17 deletions
    Original file line numberDiff line numberDiff line change
    @@ -37,7 +37,7 @@
    3737
    * Usage:
    3838
    *
    3939
    * $app = new Application('myapp', '1.0 (stable)');
    40-
    * $app->addCommand(new SimpleCommand());
    40+
    * $app->add(new SimpleCommand());
    4141
    * $app->run();
    4242
    *
    4343
    * @author Fabien Potencier <fabien.potencier@symfony-project.com>
    @@ -74,8 +74,8 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
    7474
    new DialogHelper(),
    7575
    ));
    7676

    77-
    $this->addCommand(new HelpCommand());
    78-
    $this->addCommand(new ListCommand());
    77+
    $this->add(new HelpCommand());
    78+
    $this->add(new ListCommand());
    7979

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

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

    186186
    $this->runningCommand = $command;
    187187
    $statusCode = $command->run($input, $output);
    @@ -329,7 +329,7 @@ public function getLongVersion()
    329329
    */
    330330
    public function register($name)
    331331
    {
    332-
    return $this->addCommand(new Command($name));
    332+
    return $this->add(new Command($name));
    333333
    }
    334334

    335335
    /**
    @@ -340,7 +340,7 @@ public function register($name)
    340340
    public function addCommands(array $commands)
    341341
    {
    342342
    foreach ($commands as $command) {
    343-
    $this->addCommand($command);
    343+
    $this->add($command);
    344344
    }
    345345
    }
    346346

    @@ -353,7 +353,7 @@ public function addCommands(array $commands)
    353353
    *
    354354
    * @return Command The registered command
    355355
    */
    356-
    public function addCommand(Command $command)
    356+
    public function add(Command $command)
    357357
    {
    358358
    $command->setApplication($this);
    359359

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

    389-
    $helpCommand = $this->getCommand('help');
    389+
    $helpCommand = $this->get('help');
    390390
    $helpCommand->setCommand($command);
    391391

    392392
    return $helpCommand;
    @@ -402,7 +402,7 @@ public function getCommand($name)
    402402
    *
    403403
    * @return Boolean true if the command exists, false otherwise
    404404
    */
    405-
    public function hasCommand($name)
    405+
    public function has($name)
    406406
    {
    407407
    return isset($this->commands[$name]) || isset($this->aliases[$name]);
    408408
    }
    @@ -451,7 +451,7 @@ public function findNamespace($namespace)
    451451
    /**
    452452
    * Finds a command by name or alias.
    453453
    *
    454-
    * Contrary to getCommand, this command tries to find the best
    454+
    * Contrary to get, this command tries to find the best
    455455
    * match if you give it an abbreviation of a name or alias.
    456456
    *
    457457
    * @param string $name A command name or a command alias
    @@ -460,7 +460,7 @@ public function findNamespace($namespace)
    460460
    *
    461461
    * @throws \InvalidArgumentException When command name is incorrect or ambiguous
    462462
    */
    463-
    public function findCommand($name)
    463+
    public function find($name)
    464464
    {
    465465
    // namespace
    466466
    $namespace = '';
    @@ -481,7 +481,7 @@ public function findCommand($name)
    481481

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

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

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

    506506
    /**
    @@ -512,7 +512,7 @@ public function findCommand($name)
    512512
    *
    513513
    * @return array An array of Command instances
    514514
    */
    515-
    public function getCommands($namespace = null)
    515+
    4746 public function all($namespace = null)
    516516
    {
    517517
    if (null === $namespace) {
    518518
    return $this->commands;
    @@ -566,7 +566,7 @@ static public function getAbbreviations($names)
    566566
    */
    567567
    public function asText($namespace = null)
    568568
    {
    569-
    $commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
    569+
    $commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
    570570

    571571
    $messages = array($this->getHelp(), '');
    572572
    if ($namespace) {
    @@ -607,7 +607,7 @@ public function asText($namespace = null)
    607607
    */
    608608
    public function asXml($namespace = null, $asDom = false)
    609609
    {
    610-
    $commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
    610+
    $commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
    611611

    612612
    $dom = new \DOMDocument('1.0', 'UTF-8');
    613613
    $dom->formatOutput = true;

    src/Symfony/Component/Console/Command/HelpCommand.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -65,7 +65,7 @@ public function setCommand(Command $command)
    6565
    protected function execute(InputInterface $input, OutputInterface $output)
    6666
    {
    6767
    if (null === $this->command) {
    68-
    $this->command = $this->application->getCommand($input->getArgument('command_name'));
    68+
    $this->command = $this->application->get($input->getArgument('command_name'));
    6969
    }
    7070

    7171
    if ($input->getOption('xml')) {

    src/Symfony/Component/Console/Shell.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -97,7 +97,7 @@ protected function autocompleter($text, $position)
    9797

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

    103103
    // options and arguments?

    src/Symfony/Component/DomCrawler/Form.php

    Lines changed: 16 additions & 16 deletions
    Original file line numberDiff line numberDiff line change
    @@ -215,7 +215,7 @@ public function getMethod()
    215215
    *
    216216
    * @return Boolean true if the field exists, false otherwise
    217217
    */
    218-
    public function hasField($name)
    218+
    public function has($name)
    219219
    {
    220220
    return isset($this->fields[$name]);
    221221
    }
    @@ -229,9 +229,9 @@ public function hasField($name)
    229229
    *
    230230
    * @throws \InvalidArgumentException When field is not present in this form
    231231
    */
    232-
    public function getField($name)
    232+
    public function get($name)
    233233
    {
    234-
    if (!$this->hasField($name)) {
    234+
    if (!$this->has($name)) {
    235235
    throw new \InvalidArgumentException(sprintf('The form has no "%s" field', $name));
    236236
    }
    237237

    @@ -245,7 +245,7 @@ public function getField($name)
    245245
    *
    246246
    * @return FormField The field instance
    247247
    */
    248-
    public function setField(Field\FormField $field)
    248+
    public function set(Field\FormField $field)
    249249
    {
    250250
    $this->fields[$field->getName()] = $field;
    251251
    }
    @@ -255,7 +255,7 @@ public function setField(Field\FormField $field)
    255255
    *
    256256
    * @return array An array of fields
    257257
    */
    258-
    public function getFields()
    258+
    public function all()
    259259
    {
    260260
    return $this->fields;
    261261
    }
    @@ -280,21 +280,21 @@ protected function initialize()
    280280
    $nodeName = $node->nodeName;
    281281

    282282
    if ($node === $button) {
    283-
    $this->setField(new Field\InputFormField($node));
    283+
    $this->set(new Field\InputFormField($node));
    284284
    } elseif ('select' == $nodeName || 'input' == $nodeName && 'checkbox' == $node->getAttribute('type')) {
    285-
    $this->setField(new Field\ChoiceFormField($node));
    285+
    $this->set(new Field\ChoiceFormField($node));
    286286
    } elseif ('input' == $nodeName && 'radio' == $node->getAttribute('type')) {
    287-
    if ($this->hasField($node->getAttribute('name'))) {
    288-
    $this->getField($node->getAttribute('name'))->addChoice($node);
    287+
    if ($this->has($node->getAttribute('name'))) {
    288+
    $this->get($node->getAttribute('name'))->addChoice($node);
    289289
    } else {
    290-
    $this->setField(new Field\ChoiceFormField($node));
    290+
    $this->set(new Field\ChoiceFormField($node));
    291291
    }
    292292
    } elseif ('input' == $nodeName && 'file' == $node->getAttribute('type')) {
    293-
    $this->setField(new Field\FileFormField($node));
    293+
    $this->set(new Field\FileFormField($node));
    294294
    } elseif ('input' == $nodeName && !in_array($node->getAttribute('type'), array('submit', 'button', 'image'))) {
    295-
    $this->setField(new Field\InputFormField($node));
    295+
    $this->set(new Field\InputFormField($node));
    296296
    } elseif ('textarea' == $nodeName) {
    297-
    $this->setField(new Field\TextareaFormField($node));
    297+
    $this->set(new Field\TextareaFormField($node));
    298298
    }
    299299
    }
    300300
    }
    @@ -308,7 +308,7 @@ protected function initialize()
    308308
    */
    309309
    public function offsetExists($name)
    310310
    {
    311-
    return $this->hasField($name);
    311+
    return $this->has($name);
    312312
    }
    313313

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

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

    src/Symfony/Component/EventDispatcher/Event.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -102,7 +102,7 @@ public function isProcessed()
    102102
    *
    103103
    * @return array The event parameters
    104104
    */
    105-
    public function getParameters()
    105+
    public function all()
    106106
    {
    107107
    return $this->parameters;
    108108
    }
    @@ -114,7 +114,7 @@ public function getParameters()
    114114
    *
    115115
    * @return Boolean true if the parameter exists, false otherwise
    116116
    */
    117-
    public function hasParameter($name)
    117+
    public function has($name)
    118118
    {
    119119
    return array_key_exists($name, $this->parameters);
    120120
    }
    @@ -128,7 +128,7 @@ public function hasParameter($name)
    128128
    *
    129129
    * @throws \InvalidArgumentException When parameter doesn't exists for this event
    130130
    */
    131-
    public function getParameter($name)
    131+
    public function get($name)
    132132
    {
    133133
    if (!array_key_exists($name, $this->parameters)) {
    134134
    throw new \InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
    @@ -143,7 +143,7 @@ public function getParameter($name)
    143143
    * @param string $name The parameter name
    144144
    * @param mixed $value The parameter value
    145145
    */
    146-
    public function setParameter($name, $value)
    146+
    public function set($name, $value)
    147147
    {
    148148
    $this->parameters[$name] = $value;
    149149
    }

    src/Symfony/Component/HttpFoundation/HeaderBag.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -145,11 +145,11 @@ public function contains($key, $value)
    145145
    }
    146146

    147147
    /**
    148-
    * Deletes a header.
    148+
    * Removes a header.
    149149
    *
    150150
    * @param string $key The HTTP header name
    151151
    */
    152-
    public function delete($key)
    152+
    public function remove($key)
    153153
    {
    154154
    $key = strtr(strtolower($key), '_', '-');
    155155

    src/Symfony/Component/HttpFoundation/ParameterBag.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -105,11 +105,11 @@ public function has($key)
    105105
    }
    106106

    107107
    /**
    108-
    * Deletes a parameter.
    108+
    * Removes a parameter.
    109109
    *
    110110
    * @param string $key The key
    111111
    */
    112-
    public function delete($key)
    112+
    public function remove($key)
    113113
    {
    114114
    unset($this->parameters[$key]);
    115115
    }

    0 commit comments

    Comments
     (0)
    0