Skip to content

Commit

Permalink
Rename from_attributes as use_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Sep 9, 2023
1 parent 5a56b18 commit 035357c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -11,15 +11,15 @@ The **icanboogie/bind-routing** package binds [ICanBoogie/Routing][] to [ICanBoo

#### Installation

```bash
```shell
composer require icanboogie/bind-routing
```



## Defining routes using attributes

The easiest way to define routes is to use routing attributes such as [Route][] or [Get][] to tag your controller and actions. Using any of these tags triggers the registration of the controller as a service (if it is not already registered), and the tagging with `action_responder` and `action_alias`.
The easiest way to define routes is to use attributes such as [Route][] or [Get][] to tag your controller and actions. Using any of these tags triggers the registration of the controller as a service (if it is not already registered), and the tagging with `action_responder` and `action_alias`.

The following example demonstrates how the [Route][] attribute can be used at the class level to specify a prefix for all the actions of a controller. The [Get][] and [Post][] attributes are used to tag actions. If left undefined, the action is inferred from the controller class and the method name.

Expand Down Expand Up @@ -58,7 +58,7 @@ final SkillController extends ControllerAbstract
}
```

Using the `from_attributes()` method, the config builder can collect these attributes to configure itself.
Use the `use_attributes()` method to configure the builder using attributes:

```php
<?php
Expand All @@ -68,7 +68,7 @@ namespace App;

use ICanBoogie\Binding\Routing\ConfigBuilder;

return fn(ConfigBuilder $config) => $config->from_attributes();
return fn(ConfigBuilder $config) => $config->use_attributes();
```


Expand Down
6 changes: 3 additions & 3 deletions lib/ConfigBuilder.php
Expand Up @@ -33,16 +33,16 @@ public function build(): RouteProvider
}

/**
* Builds configuration from the {@link Route} attribute.
* Configures using {@link Route} attributes.
*
* @return $this
*/
public function from_attributes(): self
public function use_attributes(): self
{
if (!class_exists(Attributes::class)) {
throw new LogicException(
sprintf(
"Unable to build from attributes, the class %s is not available",
"Unable configure using attributes, the class %s is not available",
Attributes::class
)
);
Expand Down
2 changes: 1 addition & 1 deletion tests/app/all/config/routes.php
Expand Up @@ -14,4 +14,4 @@
return fn(ConfigBuilder $config) => $config
->route('/', 'pages:home')
->get('/dance-sessions/:slug.html', 'dance-sessions:show')
->from_attributes();
->use_attributes();
2 changes: 1 addition & 1 deletion tests/lib/ConfigBuilderTest.php
Expand Up @@ -13,7 +13,7 @@ final class ConfigBuilderTest extends TestCase
public function test_from_route_attribute(): void
{
$config = (new ConfigBuilder())
->from_attributes()
->use_attributes()
->build();

$route_for_action = fn(string $action)
Expand Down

0 comments on commit 035357c

Please sign in to comment.