<?php
namespace PortalPeopleStatis\modules\SatisfyManager\controllers;

// No Yii2 Controller inheritance
use PortalPeopleStatis\modules\SatisfyManager\forms\RepositoryForm;
use PortalPeopleStatis\modules\SatisfyManager\services\NotificationService;
use Yiisoft\Yii\ViewRenderer\ViewRenderer;
use Yiisoft\Validator\Validator;

class RepositoryController
    function actionIndex()
    {
        $repoRepository = new \PortalPeopleStatis\modules\SatisfyManager\repositories\RepositoryRepository(
            new \Yiisoft\Db\Connection(/* DB config here */)
        );
        $repositories = $repoRepository->findAll();
        return $this->viewRenderer->render('repository/index', ['repositories' => $repositories]);
    }
{
    public $validator;
    public $notificationService;
    private $viewRenderer;

    function __construct(ViewRenderer $viewRenderer)
    {
        $this->validator = new Validator();
        $this->notificationService = new NotificationService();
        $this->viewRenderer = $viewRenderer;
    }

    function actionCreate()
    {
        $form = new RepositoryForm();
        $message = '';
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $form->setName($_POST['name'] ?? '');
            $form->setUrl($_POST['url'] ?? '');
            $result = $this->validator->validate($form);
            if ($result->isValid()) {
                $repoRepository = new \PortalPeopleStatis\modules\SatisfyManager\repositories\RepositoryRepository(
                    new \Yiisoft\Db\Connection(/* DB config here */)
                );
                $repo = new \PortalPeopleStatis\modules\SatisfyManager\models\Repository([
                    'name' => $form->getName(),
                    'type' => $form->getType(),
                    'url' => $form->getUrl(),
                ]);
                $repoRepository->save($repo);
                $this->notificationService->sendEmail(
                    'New Repository Added',
                    'Repository: ' . $form->getName() . ' URL: ' . $form->getUrl(),
                    'admin@example.com'
                );
                $message = 'Repository added and email sent!';
            } else {
                $message = implode(' ', $result->getErrorMessages());
            }
        }
        return $this->viewRenderer->render('repository/create', ['form' => $form, 'message' => $message]);
    }
}
