Skip to content

Commit

Permalink
Merge branch 'master' into 6.x
Browse files Browse the repository at this point in the history
* master:
  [AdminBundle] Finish version checker deprecations
  [TranslatorBundle] Remove forced import from admin interface
  [TranslatorBundle] Remove incorrect deprecation, class will be renamed
  [AdminBundle] New login styling (#2888)
  • Loading branch information
acrobat committed Jul 27, 2021
2 parents 5c8d308 + d5d7cf1 commit 455c076
Show file tree
Hide file tree
Showing 42 changed files with 19,748 additions and 240 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ src/Kunstmaan/GeneratorBundle/Resources/SensioGeneratorBundle/skeleton/layout/gr
.php_cs
.php_cs.cache
.phpunit.result.cache
!src/Kunstmaan/AdminBundle/Tests/Helper/VersionCheck/testdata/composer_*/composer.lock
2 changes: 1 addition & 1 deletion UPGRADE-5.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ security:
- { path: ^/([^/]*)/admin/reset.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
...
```

* The constructor arguments of `Kunstmaan\AdminBundle\Helper\VersionCheck\VersionChecker` have changed, inject the correct/required services/parameters.

AdminlistBundle
------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;

final class NewPasswordType extends AbstractType
Expand All @@ -23,10 +22,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'second_options' => [
'label' => 'settings.user.repeatedpassword',
],
'attr' => [
'autocomplete' => 'new-password',
],
])
->add('submit', SubmitType::class, [
'label' => 'security.resetting.reset',
'attr' => ['class' => 'btn btn-primary btn--raise-on-hover'],
]);
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Kunstmaan\AdminBundle\Form\Authentication;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

Expand All @@ -13,12 +12,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', TextType::class, [
'label' => 'settings.user.email',
'attr' => ['class' => 'form-control form-group--icon-in-control__form-control'],
'label' => 'security.resetting.email',
'required' => true,
])
->add('submit', SubmitType::class, [
'label' => 'settings.user.password',
'attr' => ['class' => 'btn btn-primary btn--raise-on-hover'],
]);
;
}
}
101 changes: 71 additions & 30 deletions src/Kunstmaan/AdminBundle/Helper/VersionCheck/VersionChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class VersionChecker
{
public const CACHE_KEY = 'version_check';

/**
* @var ContainerInterface
*/
private $container;

/**
* @var AdapterInterface
*/
Expand Down Expand Up @@ -52,35 +48,86 @@ class VersionChecker
*/
private $translator;

/** @var RequestStack */
private $requestStack;
/** @var string */
private $websiteTitle;
/** @var string */
private $projectDir;

/**
* @param CacheProvider|AdapterInterface $cache
* @param CacheProvider|AdapterInterface|ContainerInterface $cache
* @param TranslatorInterface|LegacyTranslatorInterface $translator
* @param RequestStack $requestStack
*/
public function __construct(ContainerInterface $container, /* AdapterInterface */ $cache, $translator)
{
$this->container = $container;
public function __construct(
/* ContainerInterface $container, */
/* AdapterInterface */ $cache,
$translator,
/* RequestStack */ $requestStack = null,
string $webserviceUrl = null,
int $cacheTimeframe = null,
bool $enabled = null,
string $projectDir = null,
string $websiteTitle = null
) {
if (func_num_args() === 3 && $cache instanceof ContainerInterface) {
@trigger_error(sprintf('Passing an instance of "%s" as the first argument in "%s" is deprecated since KunstmaanAdminBundle 5.9 and the service parameter types will change in KunstmaanAdminBundle 6.0. Check the constructor arguments and inject the required services and parameters instead.', ContainerInterface::class, __METHOD__), E_USER_DEPRECATED);
}

if (!$cache instanceof CacheProvider && !$cache instanceof AdapterInterface) {
if ((func_num_args() >= 2 && func_num_args() < 4) && !$cache instanceof ContainerInterface) {
// NEXT_MAJOR Remove check
throw new \InvalidArgumentException(sprintf('The first parameter of "%s" is not of the correct type, inject the correct services and parameters instead.', __METHOD__));
}

if (!$cache instanceof ContainerInterface && (!$cache instanceof CacheProvider && !$cache instanceof AdapterInterface)) {
// NEXT_MAJOR Add AdapterInterface typehint for the $cache parameter
throw new \InvalidArgumentException(sprintf('The "$cache" parameter should extend from "%s" or implement "%s"', CacheProvider::class, AdapterInterface::class));
}

$this->cache = $cache;
if ($cache instanceof CacheProvider) {
if ($cache instanceof ContainerInterface && (!$translator instanceof CacheProvider && !$translator instanceof AdapterInterface)) {
// NEXT_MAJOR Add AdapterInterface typehint for the $cache parameter
throw new \InvalidArgumentException(sprintf('The "$cache" parameter should extend from "%s" or implement "%s"', CacheProvider::class, AdapterInterface::class));
}

$cacheParam = $cache instanceof ContainerInterface ? $translator : $cache;
$this->cache = $cacheParam;
if ($this->cache instanceof CacheProvider) {
@trigger_error(sprintf('Passing an instance of "%s" as the second argument in "%s" is deprecated since KunstmaanAdminBundle 5.7 and an instance of "%s" will be required in KunstmaanAdminBundle 6.0.', CacheProvider::class, __METHOD__, AdapterInterface::class), E_USER_DEPRECATED);

$this->cache = new DoctrineAdapter($cache);
$this->cache = new DoctrineAdapter($cacheParam);
}

// NEXT_MAJOR Add "Symfony\Contracts\Translation\TranslatorInterface" typehint when sf <4.4 support is removed.
if (!$translator instanceof TranslatorInterface && !$translator instanceof LegacyTranslatorInterface) {
if (!$cache instanceof ContainerInterface && (!$translator instanceof TranslatorInterface && !$translator instanceof LegacyTranslatorInterface)) {
throw new \InvalidArgumentException(sprintf('The "$translator" parameter should be instance of "%s" or "%s"', TranslatorInterface::class, LegacyTranslatorInterface::class));
}

$this->translator = $translator;
if ($cache instanceof ContainerInterface && (!$requestStack instanceof TranslatorInterface && !$requestStack instanceof LegacyTranslatorInterface)) {
throw new \InvalidArgumentException(sprintf('The "$translator" parameter should be instance of "%s" or "%s"', TranslatorInterface::class, LegacyTranslatorInterface::class));
}

$translatorParam = $cache instanceof ContainerInterface ? $requestStack : $translator;
$this->translator = $translatorParam;

if (!$cache instanceof ContainerInterface) {
$this->requestStack = $requestStack;
$this->webserviceUrl = $webserviceUrl;
$this->cacheTimeframe = $cacheTimeframe;
$this->enabled = $enabled;
$this->projectDir = $projectDir;
$this->websiteTitle = $websiteTitle;

$this->webserviceUrl = $this->container->getParameter('version_checker.url');
$this->cacheTimeframe = $this->container->getParameter('version_checker.timeframe');
$this->enabled = $this->container->getParameter('version_checker.enabled');
return;
}

$container = $cache;
$this->requestStack = $container->get('request_stack');
$this->webserviceUrl = $container->getParameter('version_checker.url');
$this->cacheTimeframe = $container->getParameter('version_checker.timeframe');
$this->enabled = $container->getParameter('version_checker.enabled');
$this->projectDir = $container->getParameter('kernel.project_dir');
$this->websiteTitle = $container->getParameter('kunstmaan_admin.website_title');
}

/**
Expand Down Expand Up @@ -123,17 +170,16 @@ public function check()
return;
}

$host = $this->container->get('request_stack')->getCurrentRequest()->getHttpHost();
$console = realpath($this->container->get('kernel')->getProjectDir() . '/bin/console');
$host = $this->requestStack->getCurrentRequest()->getHttpHost();
$console = realpath($this->projectDir . '/bin/console');
$installed = filectime($console);
$bundles = $this->parseComposer();
$title = $this->container->getParameter('kunstmaan_admin.website_title');

$jsonData = json_encode([
'host' => $host,
'installed' => $installed,
'bundles' => $bundles,
'project' => $this->translator->trans($title),
'project' => $this->translator->trans($this->websiteTitle),
]);

try {
Expand Down Expand Up @@ -187,10 +233,7 @@ public function setClient($client)
*/
protected function getLockPath()
{
$kernel = $this->container->get('kernel');
$rootPath = $kernel->getProjectDir();

return $rootPath . '/composer.lock';
return $this->projectDir . '/composer.lock';
}

/**
Expand All @@ -202,17 +245,15 @@ protected function getLockPath()
*/
protected function getPackages()
{
$translator = $this->container->get('translator');
$errorMessage = $translator->trans('settings.version.error_parsing_composer');

$composerPath = $this->getLockPath();
if (!file_exists($composerPath)) {
throw new ParseException($translator->trans('settings.version.composer_lock_not_found'));
throw new ParseException($this->translator->trans('settings.version.composer_lock_not_found'));
}

$json = file_get_contents($composerPath);
$result = json_decode($json, true);

$errorMessage = $this->translator->trans('settings.version.error_parsing_composer');
if (json_last_error() !== JSON_ERROR_NONE) {
throw new ParseException($errorMessage . ' (#' . json_last_error() . ')');
}
Expand Down
10 changes: 9 additions & 1 deletion src/Kunstmaan/AdminBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ services:

kunstmaan_admin.versionchecker:
class: Kunstmaan\AdminBundle\Helper\VersionCheck\VersionChecker
arguments: ['@service_container', '@cache.kunstmaan_versioncheck', '@translator']
arguments:
- '@cache.kunstmaan_versioncheck'
- '@translator'
- '@request_stack'
- '%version_checker.url%'
- '%version_checker.timeframe%'
- '%version_checker.enabled%'
- '%kernel.project_dir%'
- '%kunstmaan_admin.website_title%'
public: true

kunstmaan_admin.cache:
Expand Down
15,181 changes: 15,152 additions & 29 deletions src/Kunstmaan/AdminBundle/Resources/public/css/style.css

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 455c076

Please sign in to comment.