Skip to content

Commit

Permalink
Merge pull request #514 from loic425/remove-monofony-guide
Browse files Browse the repository at this point in the history
Remove Monofony guide
  • Loading branch information
loic425 authored Jan 13, 2025
2 parents a2756ea + d809635 commit e912a23
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions REMOVE_MONOFONY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Remove Monofony guide

## Applications using the AdminPack

### Configure the admin menu

On `AdminMenuBuilder.php`, remove dependency to `AdminMenuBuilderInterface` and add an autoconfigure tag to configure the Knp menu yourself.

```php
// src/Menu/AdminMenuBuilder.php
// ...
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag(name: 'knp_menu.menu_builder', attributes: [
'method' => 'createMenu',
'alias' => 'app.admin.main',
])]
final class AdminMenuBuilder
// ...
```

### Configure the dashboard statistics

Add the following `StatisticInterface`:

```php
// src/Dashboard/DashboardStatisticsProvider.php
declare(strict_types=1);

namespace App\Dashboard;

use App\Dashboard\Statistics\StatisticInterface;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;

final class DashboardStatisticsProvider
{
public function __construct(
#[TaggedIterator(tag: 'app.dashboard_statistic')]
private iterable $statistics
) {
}

public function getStatistics(): array
{
/** @var string[] $statistics */
$statistics = [];

foreach ($this->statistics as $statistic) {
if (!$statistic instanceof StatisticInterface) {
throw new \LogicException(sprintf('Class %s must implement %s', get_class($statistic), StatisticInterface::class));
}

$statistics[] = $statistic->generate();
}

return $statistics;
}
}
```

Add the following `DashboardStatisticsProvider`:

```php
declare(strict_types=1);

namespace App\Dashboard\Statistics;

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag(name: 'app.dashboard_statistic')]
interface StatisticInterface
{
public function generate(): string;
}
```

Implements the new StatisticInterface you just created before on all your services that implement `StatisticInterface`

```diff
-use Monofony\Component\Admin\Dashboard\Statistics\StatisticInterface;
+use App\Dashboard\Statistics\StatisticInterface;
```

Update the DashboardController

```diff
// src/Controller/DashboardController.php
// ...
-use Monofony\Contracts\Admin\Dashboard\DashboardStatisticsProviderInterface;
+use App\Dashboard\DashboardStatisticsProvider;
// ...

final class DashboardController
{
public function __construct(
-private DashboardStatisticsProviderInterface $statisticsProvider,
+private DashboardStatisticsProvider $statisticsProvider,
private Environment $twig,
) {
}

// ...
}
```

### Add some autowiring configuration

```yaml
# config/services.yaml
# ...
services:
# ...
Doctrine\Persistence\ObjectManager: '@doctrine.orm.entity_manager'
Sylius\Component\User\Security\Generator\GeneratorInterface: '@sylius.app_user.token_generator.email_verification'
```
### Remove Monofony packages
```shell
composer remove monofony/admin monofony/admin-contracts monofony/core monofony/core-bundle monofony/core-contracts
```

0 comments on commit e912a23

Please sign in to comment.