-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upload avatar. * Show avatar. * Store uploaded image in database. Add twig filter to convert to base64 string.
- Loading branch information
Showing
14 changed files
with
316 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FrankProjects\UltimateWarfare\Form; | ||
|
||
use FrankProjects\UltimateWarfare\Entity\User; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\FileType; | ||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Validator\Constraints\Image; | ||
|
||
class UploadAvatarType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->setAction('/game/account/upload_avatar') | ||
->add( | ||
'avatar', | ||
FileType::class, | ||
[ | ||
'mapped' => false, | ||
'label' => 'label.avatar', | ||
'constraints' => [ | ||
new Image([ | ||
'maxSize' => '1024k', | ||
]) | ||
], | ||
] | ||
) | ||
->add( | ||
'submit', | ||
SubmitType::class, | ||
[ | ||
'label' => 'label.upload' | ||
] | ||
); | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults( | ||
array( | ||
'data_class' => User::class, | ||
'translation_domain' => 'account' | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FrankProjects\UltimateWarfare\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFilter; | ||
|
||
class Base64EncodeExtension extends AbstractExtension | ||
{ | ||
public const GET_CONTENT_FROM_STREAM = 'stream'; | ||
|
||
public function getFilters(): array | ||
{ | ||
return [ | ||
new TwigFilter('base64_encode', [$this, 'base64Encode']), | ||
]; | ||
} | ||
|
||
public function base64Encode(mixed $string, string $modifier = ''): string | ||
{ | ||
$content = match ($modifier) { | ||
self::GET_CONTENT_FROM_STREAM => stream_get_contents($string), | ||
default => (string) $string, | ||
}; | ||
return base64_encode((string) $content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.