PageSpeedInsights API V5 Return Overall Speed Score - pagespeed

I've tried using V4, which returns a metric ruleGroups" looking like this:
{
"SPEED": {
"score": 10
In V5, it seems that this metric is omitted, is there a way to include it?
Note: It should return

Actually, its there. Check results carefully.
"lighthouseResult" :{
.
.
.
.
"categories" : {
"performance": {
"score" : 1,
.
.
.
.
}
}
}

Related

Using regex to negate a filter in wiremock jsonpath

I am using wiremock for stubbing and it uses Jayway JsonPath.
I want to create a stub only when the json element doesn't contain exactly 10 digits.
stub is
"request": {
"bodyPatterns": [
{
"matchingJsonPath": "$.employees[?(#.employeeContact =~/[^0-9]{10}/)]"
}
]
}
I have tried multiple combinations like:
1. $.employees[?(#.employeeContact =~/[^0-9]{10}/)]
2. $.employees[?(#.employeeContact =~/^[0-9]{10}/)]
3. $.employees[?(#.employeeContact !=~/[0-9]{10}/)]
4. $.employees[?(#.employeeContact <>~/[^0-9]{10}/)]
But none of these have worked.
Example json which should NOT work:
{
"employee": {
"employeeContact": "1234567890"
}
}
while these employee should work (anything other than 10 digits):
1. "employeeContact": "1a34567890" // character in between
2. "employeeContact": "12345678901" // more than 10
3. "employeeContact": "123456789" // less than 10
4. "employeeContact": "123456 89" //space
You could use the logical or operator to match for lengths less than 10 and greater than 10.
"bodyPatterns": [
"or": [
{ "matchingJsonPath": "$.employees[?(#.employeeContact =~/[^0-9]{1,9}/)]" },
{ "matchingJsonPath": "$.employees[?(#.employeeContact =~/[^0-9]{11,}/)]" }
]
]
This is what worked for me:
"bodyPatterns": [{
"matchesJsonPath": "$.employees[?(#.employeeContact =~/[^0-9]{1,9}/ || $.employees[?(#.employeeContact =~/[^0-9]{11,}/)]"
}]
Watch that it is matchesJsonPath instead of matchingJsonPath.
Even with that "or" didnt work with my wiremock 2.28.1 so may well be a wiremock bug.

Symfony validator translations

I just started using symfony validator and i really like it except translation part, currently it uses my own translator lib, but i found validator.LOCALE.xlf files where are translations for almost all languages stored, and i can't figure out how to use them.
My current validator registering code is
$container->register('validator', \Symfony\Component\Validator\Validator\ValidatorInterface::class)
->setFactory(
[
new Reference('validator.builder'),
'getValidator'
]
);
$container->register('validator.builder', \Symfony\Component\Validator\ValidatorBuilderInterface::class)
->setFactory(
[
\Symfony\Component\Validator\Validation::class,
'createValidatorBuilder'
]
)
->addMethodCall(
'setTranslator',
[
new Reference('translator') // Symfony translatorInterface
]
)
->addMethodCall(
'setTranslationDomain',
[
'messages'
]
);
It looks like i checked already whole validator structure, like RecursiveValidator, ContextualValidator, Contexts and etc, but just somewhere missing one single param, on another hand ConstraintViolationBuilder just simply takes passed translator and trying to translate constraint message through it, no attempts to use any xlf files.
Just force search through all validator library files gave no result too.
Symfony guilde didn't helped too, because it offers to use default error sentences as a translation key, and use this "keys" in your own translations files, but why copy already translated sentences to your own file, and also create a mess with keys pattern (for example i use snake case) when there is already structured files exists (i am talking about .xlf)?
Solution is to add xlf file loader to your translator, and pass it .xlf translations as a resource.
Something like that
$container->register('translator.xlf_file_loader', \Symfony\Component\Translation\Loader\XliffFileLoader::class);
$container->register('translator.php_file_loader', \Symfony\Component\Translation\Loader\PhpFileLoader::class);
$container->register('translator', \Project\Framework\Translation\Translator::class)
->addArgument(
new Reference('service_container')
)
->addMethodCall(
'addLoader',
[
'php',
new Reference('translator.php_file_loader')
]
)
->addMethodCall(
'addLoader',
[
'xlf',
new Reference('translator.xlf_file_loader')
]
)
->addMethodCall('addResource', ['php', __DIR__ . '/../translation/lt.php', 'lt'])
->addMethodCall('addResource', ['php', __DIR__ . '/../translation/en.php', 'en'])
->addMethodCall('addResource', ['php', __DIR__ . '/../translation/ru.php', 'ru'])
->addMethodCall('addResource', ['xlf', __DIR__ . '/../../vendor/symfony/validator/Resources/translations/validators.lt.xlf', 'lt'])
->addMethodCall(
'setFallbackLocales',
[
['lt']
]
);
Have you simply tried to either
change the locale in the app configuration:
# config/packages/translation.yaml
framework:
default_locale: 'en'
translator:
fallbacks: ['en']
Documentation
change the locale based on (user) input:
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
// some logic to determine the $locale
$request->setLocale($locale);
}
Documentation

Symfony doesn't remove cache by tags

Symfony version: 3.4.9
Reproducing:
$cache = new TagAwareAdapter($this->get('cache.app'));
$pagination = $cache->getItem(PostTypeDictionary::CACHE_MEDIA_PREFIX . $postType . $request->get('page', 1));
if (!$pagination->isHit()) {
$data = getSomeData();
$pagination->tag(
[
PostTypeDictionary::CACHE_MEDIA_PREFIX,
PostTypeDictionary::CACHE_MEDIA_PREFIX . $postType,
]
);
$pagination->set($data);
$cache->save($pagination);
} else {
$data = $pagination->get();
}
In redis i see two keys:
1) "zG3lSHyaSM:\x00tags\x00cache.media.01"
2) "zG3lSHyaSM:cache.media.01"
First contains: "a:2:{s:12:\"cache.media.\";i:0;s:13:\"cache.media.0\";i:0;}"
Second contains data
Then i call cache clearing by tags:
(new TagAwareAdapter($this->get('cache.app')))->invalidateTags([PostTypeDictionary::CACHE_MEDIA_PREFIX]);
Redis store one more key "zG3lSHyaSM:cache.media.\x00tags\x00", which contains: "i:1;"
And that's all, old cache available.
Another cache adapters have the same problem.
What i'm doing wrong?
I found that Symfony's cache component has a bug in a most recent version (3.4.9). I think it's related to https://github.com/symfony/cache/commit/51a9eef3091b2c06f63d8b1b98de9d101b5e0e77 . Simply downgrading to 3.4.8 solved this issue for me.

SelectTokens with not exists

I'm trying to find if there's a nice way using SelectTokens and JsonPath to find all controls with type="check" and no "options". So an example JSON could be:
Value = #"{
""subsections"": [
{
""name"": ""Subsection Name"",
""caption"": ""Subsection Caption""
},
],
""controls"": [
{ ""type"" : ""check"",
""name"" : ""Checkbox2"",
""caption"" : ""Checkbox Caption 2"",
""options"" : [
{ ""caption"" : ""Yes"" },
{ ""caption"" : ""No"" }
]
},
{ ""type"" : ""check"",
""name"" : ""Checkbox2"",
""caption"" : ""Checkbox Caption 2"",
}
]
}"
I'm trying things like: $..controls[?(#.type=='check' && !(#.options))] but I can't see any option to test for a not exists.
The only option that I can think of is getting all check types and then using Linq to filter those without options. Just wondering if there is a way to do it solely through JsonPath?
Kind regards
Sidharth

php Programming Fatal Error Class 'input' not found in /home/adminl0gin/public_html/login.php on line 21

I've been having this issue for a few days now and though I have made some progress I still have not gotten anywhere. The main issue is finding the classes and autoloading them dynamically as needed. The end result is the outputted error you see in the title of this post.
File structure is as follows
input.php
core/
classes/
init.php
loader.php
Below is the corresponding code:
login.php (Line 21)
if (input::exists()) {
init.php
if (!defined('BASE_PATH')) {
define('BASE_PATH', dirname(__FILE__) . 'classes/');
require 'loader.php';
Loader::Register();
}
loader.php
class Loader {
public static function Register() {
return spl_autoload_register(array('Loader', 'Load'));
}
public static function Load($strObjectName) {
$strObjectFilePath = BASE_PATH . $strObjectName . '.php';
if ((file_exists($strObjectFilePath) === false) || (is_readable($strObjectFilePath) === false)) {
echo "there is a problem!";return false;
}
else {
require ($strObjectFilePath);
}
}
}
error
Fatal Error Class 'input' not found in /home/adminl0gin/public_html/login.php on line 21
Current php version is 5.4.24 on a live hosted server GoDaddy
Many thanks in advance!
Have you added init.php in your login.php file?

Resources