How I can check whether a unique index exisrts and avoid recreating it?
In an entity I have:
Then I run
And run upon my db, then once I run again index is re-created:
How I can avoid the re-creation of this index?
https://redd.it/1ltq6ln
@r_php
In an entity I have:
declare(strict_types=1);
namespace App\Entity\Activity;
use App\Domain\Helper\UuidHelper;
use App\Entity\Business;
use App\Entity\BusinessTypes\ActivityOperator;
use App\Entity\Image\ImageEntity;
use App\Entity\Tags\Pivot\ActivityTag;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
#[ORM\Entity]
#[ORM\Index(name: "external_id_origin_unique", columns: ["external_id", "origin"], options: ["where" => "external_id IS NOT NULL", "unique" => true])]
class ItemFromApi
{
public const ORIGIN_API='api';
public const ORIGIN_INTERNAL='internal';
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private int $id;
#[ORM\Column(type: 'string', length: 255)]
private string $noscript;
#[ORM\Column(type: 'integer', nullable: true)]
public ?int $externalId = null;
#[ORM\Column(type: 'string', length: 255)]
public string $origin = self::ORIGIN_INTERNAL;
// Setter and getter are ommited for siplicity
}
Then I run
php bin/console doctrine:schema:update --dump-sql and generates the following sql:CREATE UNIQUE INDEX external_id_origin_unique_itinerary ON item_from_api (external_id, origin);
And run upon my db, then once I run again index is re-created:
CREATE UNIQUE INDEX external_id_origin_unique_itinerary ON item_from_api (external_id, origin);
How I can avoid the re-creation of this index?
https://redd.it/1ltq6ln
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
A Cognitive Code Analysis Tool
Cognitive Code Analysis helps you understand and improve your code by focusing on how developers actually read and process it. Understandability is a huge cost factor because \~80% time is spent on reading and understanding code.
[https://github.com/Phauthentic/cognitive-code-analysis](https://github.com/Phauthentic/cognitive-code-analysis)
Features:
* Scans source code and reports detailed cognitive complexity metrics.
* Churn analysis (requires Git) to highlight risky, frequently changed code.
* Export results as CSV, XML, or HTML.
Unlike traditional metrics like cyclomatic complexity, this tool emphasizes cognitive complexity - how hard your code is to understand. It analyzes line count, argument count, variable usage, property access, and nesting to identify the hardest parts to maintain.
You can adjust the score calculation through configuration by setting weights for each metric, allowing you to tailor the cognitive complexity scoring to your own acceptable thresholds.
I’ve used it myself to spot risky areas early in projects. Measuring cognitive complexity is tough, but there’s academic backing for this approach. Check out this paper if you're curious:
[https://dl.acm.org/doi/10.1145/3382494.3410636](https://dl.acm.org/doi/10.1145/3382494.3410636)
I'd love your constructive feedback - try it out and let me know what you think!
https://redd.it/1ltpv2a
@r_php
Cognitive Code Analysis helps you understand and improve your code by focusing on how developers actually read and process it. Understandability is a huge cost factor because \~80% time is spent on reading and understanding code.
[https://github.com/Phauthentic/cognitive-code-analysis](https://github.com/Phauthentic/cognitive-code-analysis)
Features:
* Scans source code and reports detailed cognitive complexity metrics.
* Churn analysis (requires Git) to highlight risky, frequently changed code.
* Export results as CSV, XML, or HTML.
Unlike traditional metrics like cyclomatic complexity, this tool emphasizes cognitive complexity - how hard your code is to understand. It analyzes line count, argument count, variable usage, property access, and nesting to identify the hardest parts to maintain.
You can adjust the score calculation through configuration by setting weights for each metric, allowing you to tailor the cognitive complexity scoring to your own acceptable thresholds.
I’ve used it myself to spot risky areas early in projects. Measuring cognitive complexity is tough, but there’s academic backing for this approach. Check out this paper if you're curious:
[https://dl.acm.org/doi/10.1145/3382494.3410636](https://dl.acm.org/doi/10.1145/3382494.3410636)
I'd love your constructive feedback - try it out and let me know what you think!
https://redd.it/1ltpv2a
@r_php
GitHub
GitHub - Phauthentic/cognitive-code-analysis: A Cognitive Code Complexity Analysis Tool. Cognitive complexity measures how hard…
A Cognitive Code Complexity Analysis Tool. Cognitive complexity measures how hard it is for a human to understand the code, while cyclomatic complexity measures how hard your code is to test. Under...
Any recommendations to learn easyadminbundle?
I need help I have been doing research to learn this bundle but haven’t found anything yet, I am new to symfony.
https://redd.it/1lu4n1i
@r_php
I need help I have been doing research to learn this bundle but haven’t found anything yet, I am new to symfony.
https://redd.it/1lu4n1i
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
AI Assistant for website
I have a website coded in PHP, and I would like to add an assistant that visitors can use to get answers and assistance. For example, to ask questions about how to use our ERP. Instead of searching all of our help files, it would just respond with several answers. Has anyone seen or heard of something like this? Open Source? Thanks.
https://redd.it/1lu5k54
@r_php
I have a website coded in PHP, and I would like to add an assistant that visitors can use to get answers and assistance. For example, to ask questions about how to use our ERP. Instead of searching all of our help files, it would just respond with several answers. Has anyone seen or heard of something like this? Open Source? Thanks.
https://redd.it/1lu5k54
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Named parameters vs passing an array for function with many optional arguments
In the public API of a library: given a function which has many optional named parameters, how would you feel if the stability of argument order wasn't guaranteed. Meaning that you are informally forced to use named parameters.
The alternative being to pass an array of arguments.
I feel like the benefits of the named arguments approach includes editor support, clear per-property documentation.
How would this tradeoff feel to you as a user?
https://redd.it/1lu4o0i
@r_php
In the public API of a library: given a function which has many optional named parameters, how would you feel if the stability of argument order wasn't guaranteed. Meaning that you are informally forced to use named parameters.
The alternative being to pass an array of arguments.
I feel like the benefits of the named arguments approach includes editor support, clear per-property documentation.
How would this tradeoff feel to you as a user?
https://redd.it/1lu4o0i
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
What is the chain of type juggling that makes settype($obj, 'string') return 1 for a Stringable class?
https://3v4l.org/8gDuV
https://redd.it/1luju87
@r_php
https://3v4l.org/8gDuV
https://redd.it/1luju87
@r_php
3v4l.org
Online PHP editor | output for 8gDuV
Run your php code online; get statistics, vld output and compare output from all versions.
Devs working in both PHP and Golang: how are your experiences?
I tried looking a bit at older posts, but most of them seem to fall into the "which is better" or "how do I migrate from X to Y" type of discussion, which is not what I am looking for.
Background: I'm a developer with almost 2 decades of experience in between dev and product management. Have been working with PHP since 2023, first using Symfony and currently with Laravel (new job, new framework).
I'm keeping an eye open for new positions (early stage startup, you never know), and each time I see more and more positions asking for both PHP and Go, which got me curious about how they are used together in a professional environment.
So, asking the devs who in fact work with both: how is the structure of your work? Do you work migrating legacy services from PHP to Go? Do you use them in tandem? What's your experience in this setting?
https://redd.it/1luotad
@r_php
I tried looking a bit at older posts, but most of them seem to fall into the "which is better" or "how do I migrate from X to Y" type of discussion, which is not what I am looking for.
Background: I'm a developer with almost 2 decades of experience in between dev and product management. Have been working with PHP since 2023, first using Symfony and currently with Laravel (new job, new framework).
I'm keeping an eye open for new positions (early stage startup, you never know), and each time I see more and more positions asking for both PHP and Go, which got me curious about how they are used together in a professional environment.
So, asking the devs who in fact work with both: how is the structure of your work? Do you work migrating legacy services from PHP to Go? Do you use them in tandem? What's your experience in this setting?
https://redd.it/1luotad
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
PhpStorm doesn't have to look like a big, heavy IDE 👀
Transform it into a sleek, modern editor that's a joy to code in 🤩
https://youtu.be/khWprU8Xvmg
https://redd.it/1lupc2w
@r_php
Transform it into a sleek, modern editor that's a joy to code in 🤩
https://youtu.be/khWprU8Xvmg
https://redd.it/1lupc2w
@r_php
YouTube
Make PhpStorm Look Beautiful & Clean in 10 Minutes 😍
Transform your PhpStorm from cluttered to clean! 🎨 In this quick guide, I'll show you exactly how to turn the default PhpStorm interface into a modern, distraction-free coding environment; clean & beautiful!
Make PhpStorm Look Beautiful & Clean in 10 Minutes ✨
https://youtu.be/khWprU8Xvmg
https://redd.it/1lup0dv
@r_php
https://youtu.be/khWprU8Xvmg
https://redd.it/1lup0dv
@r_php
YouTube
Make PhpStorm Look Beautiful & Clean in 10 Minutes 😍
Transform your PhpStorm from cluttered to clean! 🎨 In this quick guide, I'll show you exactly how to turn the default PhpStorm interface into a modern, distraction-free coding environment; clean & beautiful!
Laravel Serializable Closure: serialize the unserializable
https://youtu.be/SvSxH-iPpOc
https://redd.it/1lutns7
@r_php
https://youtu.be/SvSxH-iPpOc
https://redd.it/1lutns7
@r_php
YouTube
Laravel Serializable Closure: serialize the unserializable
PHP doesn’t let you serialize closures, but Laravel does, thanks to an underrated package that’s built into the framework. I show you exactly how Laravel serializable-closure works, how Laravel uses it internally, and how you can use it safely (and securely!)…
Action Pattern in Laravel: Concept, Benefits, Best Practices
https://nabilhassen.com/action-pattern-in-laravel-concept-benefits-best-practices
https://redd.it/1luvbnw
@r_php
https://nabilhassen.com/action-pattern-in-laravel-concept-benefits-best-practices
https://redd.it/1luvbnw
@r_php
Nabilhassen
Action Pattern in Laravel: Concept, Benefits, Best Practices
The Laravel Action Pattern organizes business logic into reusable, testable classes. It enables context-independent actions for maintainable code.
Laravel Livewire + FrankenPHP + Mercure Demo
I built a quick demo using Laravel Livewire, FrankenPHP, and Mercure
Repo: https://github.com/besrabasant/frakenphp-demo
https://redd.it/1lv9d75
@r_php
I built a quick demo using Laravel Livewire, FrankenPHP, and Mercure
Repo: https://github.com/besrabasant/frakenphp-demo
https://redd.it/1lv9d75
@r_php
GitHub
GitHub - besrabasant/frakenphp-demo
Contribute to besrabasant/frakenphp-demo development by creating an account on GitHub.
Laravel Livewire + FrankenPHP + Mercure Demo
I built a quick demo using Laravel Livewire, FrankenPHP, and Mercure
Repo: https://github.com/besrabasant/frakenphp-demo
https://redd.it/1lv9e8h
@r_php
I built a quick demo using Laravel Livewire, FrankenPHP, and Mercure
Repo: https://github.com/besrabasant/frakenphp-demo
https://redd.it/1lv9e8h
@r_php
GitHub
GitHub - besrabasant/frakenphp-demo
Contribute to besrabasant/frakenphp-demo development by creating an account on GitHub.
Another recount on breaking into a retired PHP app (RainLoop) using textbook vulnerabilities (unserialize, not checking file paths, etc.).
Unlike the other time, it seems there is no English text available, so just a short recount by yours truly.
Although RainLoop web-mail client looks extremely dated, and its Github repo is in the archived state, it was listed as an obscure web-mail option by a Beget cloud platform, and hence was eligible for their bug bounty program. So a bug hunter nicknamed hunter decided to dig in.
And so how it went:
`+` unserializse, fed by cookie input in RainLoop\Utils::DecodeKeyValuesQ()
`+` curl is fed by invalidated user-supplied data allowing file:// scheme in RainLoop\Actions\DoComposeUploadExternals()
`+` attached files are not checked for validity, hence
create a new mail with an arbitrary attach file
save it as a Draft and check the HTTP request
modify it so the attachment becomes file:///var/www/html/data/SALT.php (it's unclear how the path was discovered but it's doable, like via guesswork or relative path)
check whatever attachment hash returned by the system
use that hash to forge a request for attachment
bingo, we have SALT.php attached.
Now the story goes on creating the executable payload. The list of used libraries were examined and Predis was targeted, starting from destructor method in \Predis\Response\Iterator\MultiBulkTuple(), resulting in POC code. And then, once MultiBulkTuple's desctuctor is called, Predis/Command/Processor/KeyPrefixProcessor.php would execute calluserfunc() with a command stored in DispatcherLoop::$callbacks and payload DispatcherLoop::$pubsub and the simplest command would be
Also there was a note that all this long way was really unnecessary as it turned out that gopher:// based SSRF could have directly manipulated php-fpm service. Though I am not sure how exactly it could be done, but would like to learn.
From this story I learned about file:// and gother:// protocols supported by curl, the latter being effectively a telnet client which can be used to connect any TCP service by asking curl to open a gother:://service:port/payload URL.
https://redd.it/1lvftxe
@r_php
Unlike the other time, it seems there is no English text available, so just a short recount by yours truly.
Although RainLoop web-mail client looks extremely dated, and its Github repo is in the archived state, it was listed as an obscure web-mail option by a Beget cloud platform, and hence was eligible for their bug bounty program. So a bug hunter nicknamed hunter decided to dig in.
And so how it went:
`+` unserializse, fed by cookie input in RainLoop\Utils::DecodeKeyValuesQ()
- that input is encrypted with a long key stored in SALT.php`+` curl is fed by invalidated user-supplied data allowing file:// scheme in RainLoop\Actions\DoComposeUploadExternals()
- there is no direct way to get the output`+` attached files are not checked for validity, hence
create a new mail with an arbitrary attach file
save it as a Draft and check the HTTP request
modify it so the attachment becomes file:///var/www/html/data/SALT.php (it's unclear how the path was discovered but it's doable, like via guesswork or relative path)
check whatever attachment hash returned by the system
use that hash to forge a request for attachment
bingo, we have SALT.php attached.
+ now we can create a payload for unserialize and encrypt it using the actual keyNow the story goes on creating the executable payload. The list of used libraries were examined and Predis was targeted, starting from destructor method in \Predis\Response\Iterator\MultiBulkTuple(), resulting in POC code. And then, once MultiBulkTuple's desctuctor is called, Predis/Command/Processor/KeyPrefixProcessor.php would execute calluserfunc() with a command stored in DispatcherLoop::$callbacks and payload DispatcherLoop::$pubsub and the simplest command would be
system with whatever shell command you can imagine. Also there was a note that all this long way was really unnecessary as it turned out that gopher:// based SSRF could have directly manipulated php-fpm service. Though I am not sure how exactly it could be done, but would like to learn.
From this story I learned about file:// and gother:// protocols supported by curl, the latter being effectively a telnet client which can be used to connect any TCP service by asking curl to open a gother:://service:port/payload URL.
https://redd.it/1lvftxe
@r_php
Reddit
From the PHP community on Reddit: A fantastic recount on breaking a PHP app using several textbook vulnerabilities like error reporting…
Explore this post and more from the PHP community
Need to upgrade PHP on XAMPP for Linux
Hi,
I installed XAMPP on Ubuntu Server 24.04. It comes with php 8.2.12. I need to upgrade it to 8.3.6 or later.
I tried different guides and solutions found on forums but nothing works, it also corrupted previous data saved on XAMPP folder. Has anyone had my same problem??
https://redd.it/1lvke47
@r_php
Hi,
I installed XAMPP on Ubuntu Server 24.04. It comes with php 8.2.12. I need to upgrade it to 8.3.6 or later.
I tried different guides and solutions found on forums but nothing works, it also corrupted previous data saved on XAMPP folder. Has anyone had my same problem??
https://redd.it/1lvke47
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Strange issue when trying to run commands via app
I have a strange issue, i want to execute symfony commands via app, i followed the suggestion from:
https://symfony.com/doc/current/console/command\_in\_controller.html
public function execute(CommandInterface $command): string
{
$input = new ArrayInput($command->getParameter());
$output = new BufferedOutput();
$application = new Application($this->kernel);
$application->setAutoExit(false);
$application->run($input, $output);
$converter = new AnsiToHtmlConverter();
$content = $output->fetch();
return $converter->convert($content);
}
And a relative vanilla command:
readonly class ExtractTranslationsCommand implements CommandInterface
{
public function construct(private string $locale)
{
//
}
public function getCommand(): string
{
return 'translation:extract';
}
public function getParameter(): array
{
return
'command' => $this->getCommand(),
'--format' => 'php',
'--force' => null,
$this->locale => $this->locale,
;
}
}
And i get:
Error thrown while running command "translation:extract --format=php --force en". Message: "The "en" argument does not exist."
If i run the command in the console it works fine.
if i change the last parameter from
Uncaught PHP Exception TypeError: "Symfony\Component\Console\Input\Input::escapeToken(): Argument #1 ($token) must be of type string, null given, called in /var/www/html/vendor/symfony/console/Input/ArrayInput.php on line 107" at Input.php line 154
Does anything sees an issue that might cause the errors, i mean the copy paste it it does work
translation:extract --format=php --force en
https://redd.it/1lvo7nc
@r_php
I have a strange issue, i want to execute symfony commands via app, i followed the suggestion from:
https://symfony.com/doc/current/console/command\_in\_controller.html
public function execute(CommandInterface $command): string
{
$input = new ArrayInput($command->getParameter());
$output = new BufferedOutput();
$application = new Application($this->kernel);
$application->setAutoExit(false);
$application->run($input, $output);
$converter = new AnsiToHtmlConverter();
$content = $output->fetch();
return $converter->convert($content);
}
And a relative vanilla command:
readonly class ExtractTranslationsCommand implements CommandInterface
{
public function construct(private string $locale)
{
//
}
public function getCommand(): string
{
return 'translation:extract';
}
public function getParameter(): array
{
return
'command' => $this->getCommand(),
'--format' => 'php',
'--force' => null,
$this->locale => $this->locale,
;
}
}
And i get:
Error thrown while running command "translation:extract --format=php --force en". Message: "The "en" argument does not exist."
If i run the command in the console it works fine.
if i change the last parameter from
$this->locale => $this->locale to $this->locale => null it is also not working with the error:Uncaught PHP Exception TypeError: "Symfony\Component\Console\Input\Input::escapeToken(): Argument #1 ($token) must be of type string, null given, called in /var/www/html/vendor/symfony/console/Input/ArrayInput.php on line 107" at Input.php line 154
Does anything sees an issue that might cause the errors, i mean the copy paste it it does work
translation:extract --format=php --force en
https://redd.it/1lvo7nc
@r_php
Symfony
How to Call a Command from a Controller (Symfony Docs)
The Console component documentation covers how to create a console command. This article covers how to use a console command directly from your controller. You may have the need to call some function …
L12 starter kit (Inertia/Vue) and persistent layout
Has anybody tried to implement persistent layout on the inertia+Vue starter kit?
I'm using the sidebar version, and I would like for the app not reload the layout each time and lose the opened sidebar item. And also I have to implement a chat component that has to live on the layout
I don't think it's possible to pass props (ie the breadcrumbs) from each page to the AppLayout?
https://redd.it/1lvx3he
@r_php
Has anybody tried to implement persistent layout on the inertia+Vue starter kit?
I'm using the sidebar version, and I would like for the app not reload the layout each time and lose the opened sidebar item. And also I have to implement a chat component that has to live on the layout
I don't think it's possible to pass props (ie the breadcrumbs) from each page to the AppLayout?
https://redd.it/1lvx3he
@r_php
Inertia.js Documentation
Pages - Inertia.js Documentation
Refreshing a Livewire component after closing a Flux modal.
I currently have two Livewire components, one called PatientDetails, and another PatientForm. PatientDetails is the main component, while PatientForm opens up in a FluxUI modal. At the end of the save() function in PatientForm (which either creates or updates a Patient record), I have the following:
Flux::toast($message, heading: 'Success', variant: 'success', position: 'top-right');
Flux::modal("patient-form-{$this->patient->id }")->close();
What I would like to then do is refresh the underlying PatientDetails component, so whatever has been updated can refresh. How can I go about doing this?
https://redd.it/1lw4m56
@r_php
I currently have two Livewire components, one called PatientDetails, and another PatientForm. PatientDetails is the main component, while PatientForm opens up in a FluxUI modal. At the end of the save() function in PatientForm (which either creates or updates a Patient record), I have the following:
Flux::toast($message, heading: 'Success', variant: 'success', position: 'top-right');
Flux::modal("patient-form-{$this->patient->id }")->close();
What I would like to then do is refresh the underlying PatientDetails component, so whatever has been updated can refresh. How can I go about doing this?
https://redd.it/1lw4m56
@r_php
Reddit
From the laravel community on Reddit
Explore this post and more from the laravel community