WebSocketBundle Symfony 4 integration - php

I have problem with Symfony 4 integration with GeniusesOfSymfony/WebSocketBundle, routing file for pubsub is not loading.
Installed everything
'gos/web-socket-bundle dev-master '
'gos/pubsub-router-bundle v0.3.2'
Created file _/config/packages/gos_web_socket.yaml_ with content
gos_web_socket:
server:
port: 1337 #The port the socket server will listen on
host: 127.0.0.1 #The host ip to bind to
router:
resources:
- '%kernel.project_dir%/config/pubsub.yaml'
topics:
- "#app.topic.chat"
And file '/config/pubsub.yaml' with content
app_topic_chat:
channel: 'app/chat/{first_user}/{second_user}'
handler:
callback: 'chat.topic' #related to the getName() of your topic
requirements:
first_user:
pattern: '\d+' #accept all valid regex, don't put delimiters !
second_user:
pattern: '\d+'
Getting always error
!! In DelegatingLoader.php line 37:
!!
!! Cannot load resource "/var/www/html/cms/config/pubsub.yaml".
Please help

Eh, problem was in naming.
It was
'%kernel.project_dir%/config/pubsub.yaml'
but need to be
'%kernel.project_dir%/config/pubsub.yml'
so yml not yaml

Related

Symfony 4: You have requested a non-existent parameter "locale"

When I enable the 'dev' mode in my Symfony 4 app (that is already online in a shared hosting service) it shows this message:
(1/1) ParameterNotFoundException
You have requested a non-existent parameter "locale".
in ParameterBag.php (line 100)
at ParameterBag->get('locale')
in EnvPlaceholderParameterBag.php (line 57)
at EnvPlaceholderParameterBag->get('locale')
in ParameterBag.php (line 216)
at ParameterBag->resolveString('%locale%', array('locale' => true))
in ParameterBag.php (line 187)
...
and does not allow to debug the app. My config/services.yml code is as default:
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
services:
# default configuration for Services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your Services.
autoconfigure: true # Automatically registers your Services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused Services; this also means
# fetching Services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
...
Please, someone can help me to fix this error.
Had the same problem during the fresh symfony 4.3 + sonata admin bundle installation.
As a solution I added locale parameter:
// /config/services.yaml
parameters:
locale: 'en'
While I am not a Symphony expert the documentation appears to allow anything in the parameters section, but it does mention also defining the values in the .env.dist file as well for them to be used here.
http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters
When upgrading from symfony 4.2 to symfony 4.4 I also got this error when composer commands.
This parameter seems so be used in config/packages/translation.yml.
Updating the symfony/translation recipe which no longer refers to %locale% but hardcode 'en' solves the problem for me.
Simply run composer recipes:install symfony/translation --force -v

Sonata block http cache handler sonata.cache.noop not defined

I'm trying to set up sonata block cache but when I setup the http_cache handler I'm getting an exception even when the service seems to be there.
My current test setup is the following
sonata_cache:
caches:
predis:
servers:
- {host: %redis_host%, port: %redis_port%, database: 2}
apc:
token: %secret% # token used to clear the related cache
prefix: %domain% # prefix to ensure there is no clash between instances
# servers:
# - { domain: %domain%, ip: 127.0.0.1, port: 80 }
timeout:
RCV: { sec: 5, usec: 0 }
SND: { sec: 5, usec: 0 }
sonata_block:
http_cache:
# handler: sonata.cache.noop
listener: true
I can see the multiple services that I enabled on the sonata_cache.caches
$ app/console debug:container sonata.cache.noop
[container] Information for service sonata.cache.noop
Service Id sonata.cache.noop
Class Sonata\Cache\Adapter\Cache\NoopCache
Tags
- sonata.cache ()
[...]
If I change the sonata_block setup to:
sonata_block:
http_cache:
handler: sonata.cache.noop
listener: true
I got the following exception
InvalidArgumentException in ContainerBuilder.php line 796 "The service
definition "sonata.cache.noop" does not exist."
Does anyone had a similar issue?
Try to replace :
handler: sonata.cache.noop
to :
handler: sonata.block.cache.handler.noop

Default configuration of SRIORestUploadBundle coupled with KnpGaufretteBundle doesn't work

I'd like use Symfony2 bundle SRIORestUploadBundle to handle the upload of a file through an API but after setting up the basic configuration, it still get the following error: ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58:
The service "srio_rest_upload.storage.default" has a dependency on a non-existent service "gaufrette.uploads_filesyste".
it is a typo, missing "m" after gaufrette.uploads_filesyste
I appologies for the fact I didn't do the configuration well (copy past doesn't necessary work with YAML). In fact the follwing config doesn't generate error:
knp_gaufrette:
adapters:
local_uploads:
local:
directory: %kernel.root_dir%/../web/uploads
filesystems:
uploads:
adapter: local_uploads
srio_rest_upload:
storages:
default:
filesystem: gaufrette.uploads_filesystem

How to use S3 (AWS SDK v3) to cache images generated by LiipImagineBundle

I'm trying to use the S3 Cache Resolver of LiipImagineBundle to upload my cached thumbnails to S3 but I'm exepriencing some strange issues.
I'm using the AWS SDK v ^3.2:
"aws/aws-sdk-php": "^3.2",
I'm using Symfony2 and in my services.yml, I've configured the Aws\Credentials\Credentials class and the Aws\S3\S3Client that uses it to create the client:
shq.amazon.s3Credentials:
class: Aws\Credentials\Credentials
arguments: ["%amazon.s3.key%", "%amazon.s3.secret%"]
shq.amazon.s3:
class: Aws\S3\S3Client
arguments:
- version: %amazon.s3.version%
region: %amazon.s3.region%
credentials: "#shq.amazon.s3Credentials"
All works well, and I'm able to upload files to S3.
Now, the configuration of LiipImagineBundle: it seems that LiipImagineBundle has configuration rules that apply only to AWS SDK 2 and that causes "false positives" using the aws_s3 cache resolver.
I've tried at least three different configurations.
CONFIGURATION 1: FOR AWS SDK 2
liip_imagine:
resolvers:
default:
web_path: ~
cache_s3:
aws_s3:
client_config:
key: %amazon.s3.key%
secret: %amazon.s3.secret%
region: %amazon.s3.region%
version: %amazon.s3.version%
bucket: %amazon.s3.bucket%
get_options:
Scheme: 'https'
put_options:
CacheControl: 'max-age=86400'
cache: cache_s3
filter_sets:
thumb_purchase:
filters:
thumbnail: { size: [250, 250], mode: outbound }
interlace:
mode: line
This throws an exception:
An exception has been thrown during the rendering of a template
("Error retrieving credentials from the instance profile metadata
server. (cURL error 28: Connection timed out after 1006 milliseconds
(see http://curl.haxx.se/libcurl/c/libcurl-errors.html))") in
src/AppBundle/Resources/views/Store/show.html.twig at line 135.
This is thrown by the AWS SDK that is searching for credentials and doesn't find them.
So, this approach seems not working.
CONFIGURATION 2: USING Aws\Credentials (AWS SDK 3)
The way to pass credentials to S3Client is passing an instance of Aws\Credentials. I do this through a service so I can reuse the same credentials in other services (and that works as I use it to upload files to S3!):
shq.amazon.s3Credentials:
class: Aws\Credentials\Credentials
arguments: ["%amazon.s3.key%", "%amazon.s3.secret%"]
and in config.yml the :
liip_imagine:
resolvers:
cache_thumb_purchase:
aws_s3:
client_config:
version: %amazon.s3.version%
region: %amazon.s3.region%
credentials: "#shq.amazon.s3Credentials"
bucket: %amazon.s3.bucket%
get_options:
Scheme: 'https'
put_options:
CacheControl: 'max-age=86400'
filter_sets:
thumb_purchase:
cache: cache_thumb_purchase
filters:
thumbnail: { size: [250, 250], mode: outbound } # Transforms 50x40 to 32x26, no cropping
interlace:
# mode can be one of none,line,plane,partition
mode: line
As you can see, I pass the Credentials service to LiipImagineBundle but I get this error FROM Aws\ClientResolver:
InvalidArgumentException in ClientResolver.php line 296:
Invalid configuration value provided for "credentials". Expected Aws\Credentials\CredentialsInterface|array|bool|callable, but got string '#shq.amazon.s3Credentials' (length=25)
credentials: (Aws\Credentials\CredentialsInterface|array|bool|callable)
Specifies the credentials used to sign requests. Provide an
Aws\Credentials\CredentialsInterface object, an associative array of "key",
"secret", and an optional "token" key, false to use null credentials, or
a callable credentials provider used to create credentials or return null.
See Aws\Credentials\CredentialProvider for a list of built-in credentials
providers. If no credentials are provided, the SDK will attempt to load
them from the environment.
It seems that, instead of passing the class Credentials referenced by #shq.amazon.s3Credentials, it passes simply the string #shq.amazon.s3Credentials, so the ClientResolver, correctly, reports that the passed parameter is incorrect.
So, this configuration doesn't work, too.
CONFIGURATION 3: PASSING AN ARRAY TO S3Client (AWS SDK 3)
The third way of instantiating a S3Client is passing an associative array to hardcode credentials.
So I tried this configuration:
liip_imagine:
resolvers:
cache_thumb_purchase:
aws_s3:
client_config:
version: %amazon.s3.version%
region: %amazon.s3.region%
#credentials: "#shq.amazon.s3Credentials"
credentials:
key: %amazon.s3.key%
secret: %amazon.s3.secret%
...
But this time I receive an error from LiipImagineBundle, that seems doesn't accept an array as parameter:
InvalidTypeException in ScalarNode.php line 36: Invalid type for path
"liip_imagine.resolvers.cache_thumb_purchase.aws_s3.client_config.HERE_THERE_IS_DIRECTLY_MY_AWS_KEY".
Expected scalar, but got array.
I think that the configuration rules of the bundle have to be updated but i don't know how to do this as I'm not yet so confident with such kind of things.
So, how can I make LiipImagineBundle / Symfony to pass the class instead of the string that refers to the Credentialsclass? Is a fault of mine, or is something broken in LiipImagineBundle?
(Also, strange thing that I don't understand, instead of using the term "key" in the path, it use the value of "key" that is HERE_THERE_IS_DIRECTLY_MY_AWS_KEY.
So it reports a path like this liip_imagine.resolvers.cache_thumb_purchase.aws_s3.client_config.HERE_THERE_IS_DIRECTLY_MY_AWS_KEYinstead of a path like liip_imagine.resolvers.cache_thumb_purchase.aws_s3.client_config.key - that to me seems more correct, doesn't it?).
Have you tried this?
liip_imagine:
resolvers:
cache_thumb_purchase:
aws_s3:
client_config:
credentials:
key: %amazon.s3.key%
secret: %amazon.s3.secret%
version: %amazon.s3.version%
region: %amazon.s3.region%
bucket: %amazon.s3.bucket%
get_options:
Scheme: 'https'
put_options:
CacheControl: 'max-age=86400'
filter_sets:
thumb_purchase:
cache: cache_thumb_purchase
filters:
thumbnail: { size: [250, 250], mode: outbound } # Transforms 50x40 to 32x26, no cropping
interlace:
# mode can be one of none,line,plane,partition
mode: line
services:
admin.amazon.s3:
class: Aws\S3\S3Client
factory_class: Aws\S3\S3Client
factory_method: 'factory'
arguments:
- key: %amazon.s3.key%
secret: %amazon.s3.secret%
region: %amazon.s3.region%
version: %amazon.s3.version%
I'm starting to work on this LiipImagineBundle + KnpGaufretteBundle + "aws/aws-sdk-php": "^3.18" right now

Graylog2 with Symfony 2 (Monolog)

I want to use the "Monolog -> GelfHandler" in a SF2 project. So I've added the following to my composer.json:
"graylog2/gelf-php": "dev-master"
My SF2 config.yml:
monolog:
handlers:
main:
type: gelf
publisher:
hostname: %Graylog2.Host%
port: %Graylog2.Port%
level: info
formatter: monolog.formatter.session_request
But now, if I want to log something, I get an error in GelfHandler::write()
Gelf\Publisher::publish() must be an instance of Gelf\MessageInterface, string given
What is wrong here?
ok, i will answer my question by my self. the failure is to change the "formatter" or you have to use a formatter is sub-classes from Monolog\Formatter\GelfMessageFormatter.
thx # all

Categories