Download the PHP package mmo/sf-utils without Composer
On this page you can find all versions of the php package mmo/sf-utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package sf-utils
Short Description A collection of extensions for Symfony Components
License MIT
Informations about the package sf-utils
Symfony extensions
Validators
ITIN validator
ITIN - Individual Taxpayer Identification Number
Birthday
BankRoutingNumber
Utf8Letters
Only UTF-8 letters and dashes.
Utf8Words
Only UTF-8 letters, dashes, and spaces are allowed. Useful to validate the full name of a person.
OnlyDigits
Only digits are allowed.
ArrayConstraintValidatorFactory
Validators which don't follow a convention of naming a Constraint and ConstraintValidator, will not be found by the default implementation of ConstraintValidatorFactory.
The class ArrayConstraintValidatorFactory
resolve this problem, you can map ConstraintValidator to object.
Translator
FakeTranslator
The FakeTranslator
class can be used in a unit tests instead of using a stub.
At the moment only id
and locale
arguments are supported.
Security
Encrypter
Encrypter
is used to encrypt string value.
All encrypted values are encrypted using OpenSSL and the AES-256-CBC cipher (as default).
AlwaysTheSameEncoderFactory (Symofny 4.4 and 5.4)
AlwaysTheSameEncoderFactory
is useful in integration tests with combination of UserPasswordEncoder
. No matter which implementation of UserInterface you pass,
will always be used the same password encoder injected via constructor.
MemoryUserProvider (only Symfony 4.4 nad 5.4)
For Symfony 6.4+ use build-in provider \Symfony\Component\Security\Core\User\InMemoryUserProvider
.
MemoryUserProvider
is a simple non persistent user provider for tests.
This provider compares to InMemoryUserProvider allows for store any user objects, which implement the UserInterface interface instead of only the internal Symfony User class.
Form
RamseyUuidToStringTransformer
Transforms between a UUID string, and a UUID object.
Symfony 5.3 include an own UuidToStringTransformer
transformer, but you need also use a symfony/uuid component.
This transformer works with a ramsey/uuid
library.
PrimaryKeyToEntityTransformer
Transforms between a primary key(composite primary key is not supported), and an entity.
StringInsteadNullTransformer
The goal of this transformer is to fix an error when you have a form with ChoiceType and pass an empty value for this field and your entity/DTO expect only string value you get error "Expected argument of type "string", "NULL" given at property path ...".
The Symfony changes this empty string to null value (due to ChoiceToValueTransformer). You can add StringInsteadNullTransformer as a model transformer, so null values will be transformed to an empty string.
ReplaceIfNotSubmittedListener
The goal of this EventSubscriber is to overwrite data of model, when no data has been sent. Imagine scenario, that you have entities:
Property $person is not null.
You want to set this value to null, because PersonDto cannot be in "split state".
Both properties of PersonDto has to be set (cannot be empty).
When the form is submitted, and Symfony parameter $clearMissing
of method submit
is set to false
,
then due to this EventSubscriber the property person
of FormDto
will be set to null value.
Without this EventSubscriber, an empty PersonDto object will be created which will be passed to FormDto
.
See also test \mmo\sf\tests\Form\ReplaceIfNotSubmittedFormTest
.
lexik/jwt-authentication-bundle
Revoke JWT token
The JWT is stateful token. We don't need to store them. This property create problem, when we need to revoke (invalidate) a token. Some resources: How to change a token to be invalid status? or Invalidating JSON Web Tokens
In a file config/packages/cache.yaml
we register a new pool cache.jwt
. In this example as adapter we use Redis.
In a file config/routes.yaml
we add a router:
Finally, we need to register services in config/services.yaml
file.
We create alias for interface JitGeneratorInterface
to RamseyUuid4JitGenerator
and configure listeners.
For CheckRevokeListener
we need pass correct arguments for cache pool (we create custom pool - cache.jwt
in config/packages/cache.yaml
) and router name api_logout
, which we add in a file config/routes.yaml
Util
Transliterator
Class Transliterator
contains one static method transliterate
to returns transliterated version of a string.
Based on yii2 Inflector
EntityTestHelper
The class EntityTestHelper
helps set a value for a private field e.g. id
.
ObjectHelper
arrayToObject
This static method recursive converts an array to stdClass.
Commands
S3CreateBucketCommand
Command mmo:s3:create-bucket
creates a S3 bucket.
When the option skip-if-exists
is enabled, and the bucket exists the process will finish successful.
You can use the option --public
so everyone can get objects from a bucket.
To use this command you must register two services.
In config/services.yaml
register a service s3client
and mmo\sf\Command\S3CreateBucketCommand
.
LiipImagineBundle
ResolverAlwaysStoredDecorator
This resolver always returns true whether image already exists or not.
cyve/json-schema-form-bundle
CyveJsonSchemaMapper
The default implementation of data mapper (PropertyPathMapperTest
) also set array key when the value is null
This is a problem when fields in JsonSchema are not required.
Schema validator doesn't check whether the field value is set. This is something different from the Symfony Validator component.
In Symfony if the field value is the null or empty string, the validation is skipped.
In JsonSchemaValidator event optional field with value null must match validation rules.
Also cyve/json-schema-form-bundle not supported multiple types of field.
Doctrine
IgnoreSchemaTablesListener
This listener expects table names, which will be ignored during comparing database schema with entities. It is useful when you manually manage the table's schema for some of your entities. This is a similar solution to Manual tables from DoctrineMigrationsBundle
Serializer
MyCLabsEnumNormalizer
Normalizer and denormalizer for Enum class from package myclabs/php-enum
.
MoneyNormalizer
Normalizer and denormalizer for Money class from package moneyphp/money
.
EventSubscriber
PerformanceSubscriber
This listener connects to HttpKernel events (RequestEvent and TerminateEvent) to log the performance of an endpoint via LoggerInterface. The entry in the log includes duration, HTTP method, URL, and PID. Analysis of those data allows us to find the most time-consuming endpoints. We can have some suspects and start a deeper analysis of the performance of those endpoints via Xdebug or Blackfire.
Create a new channel and handler for monolog in config/packages/monolog.yaml
.
Next register listener in config/services.yaml
.
When we refresh page in log (in this configuration logs are sent to stderr) we should see something like this:
[2021-08-30 15:15:19] performance.INFO: The request "GET /admin/login" took "1.041289" second. {"url":"/admin/login","method":"GET","pid":7,"status_code":200}