PHP Reddit – Telegram
PHP Reddit
34 subscribers
291 photos
37 videos
24.9K links
Channel to sync with /r/PHP /r/Laravel /r/Symfony. Powered by awesome @r_channels and @reddit2telegram
Download Telegram
NODEJS CAN RUN PHP !!!

based from the tweet of matteo collina : https://x.com/matteocollina/status/1927395639698096313


i was wondering if it's only like for dummy noscripts or is it legitimately a thing???




https://redd.it/1kxcpgz
@r_php
How I can make/configure make:command to place my comands into a specific directory instead of the default one?

If I need a command I type:

php bin/console make:command mycommand:dosmething


In order to make a command upon ./src/Console but a coleague of mine does a refactor ans places the commands upon ./src/Infrastructure/Console instead of the default path. Is there a way to override the make:command in order to place the generated commands upon the desired path?

https://redd.it/1kxghve
@r_php
Built a full WebRTC implementation in PHP – Feedback welcome!

Hey everyone!

I've been working on a full WebRTC implementation in PHP and just released a set of packages that handle everything from ICE, DTLS, SCTP, RTP, and SRTP to signaling and statistics.

It’s built entirely in PHP (no Node.js or JavaScript required on the backend), using PHP FFI to interface with native libraries like OpenSSL and VPX when needed. The goal is to make it easy to build WebRTC-based apps in pure PHP – including media servers, video conference web app, SFUs, and peer-to-peer apps.

GitHub: https://github.com/PHP-WebRTC

Features:

Full WebRTC stack: ICE, DTLS, SRTP, SCTP, RTP
Adapter-based signaling (WebSocket, TCP, UDP, etc.)
PHP-native SDP and stats
SFU-ready architecture
Fully asynchronous with ReactPHP

I'm actively looking for:

Feedback on architecture or API design
Suggestions for real-world use cases
Contributions, issues, or ideas from the community

If you're interested in media streaming or real-time communication with PHP, I'd love your thoughts. Also happy to answer any technical questions!

Thanks 🙏

https://redd.it/1kxnjod
@r_php
Just made footers configurable in my Laravel based ERP.

Hey r/Laravel!

I just added a flexible footer configuration system to my open-source Laravel ERP project Samarium and thought to share with you all.

What's new:

Footer templates are now completely configurable via `config/app.php`
Just set 'footer_blade_file' => 'partials.cms.website.footer.footer-name' and you're done
All footer files have access to the global `$company` object (name, phone, email, address, etc.)
Built with Bootstrap 4 classes for easy styling

Example:

If you have a footer file named footer-corporate.blade.php in the resources/views/partials/cms/website/footer directory, configure it as below in config/app.php file:

'footerbladefile' => 'partials.cms.website.footer.footer-corporate'

Had been some time that I wanted to implement this. Now that I have done it, just sharing with you all. Also, any better idea to implement this?

Repo: https://github.com/oitcode/samarium

Thanks all.

https://redd.it/1kxozw7
@r_php
Immutable value object using property hooks

before property hooks you would simply use constructor property promotion in a readonly class with getters and you're good.

readonly class ValueObject
{
public function construct(
private string $name,
private ?int $number = null,
) {
}

public function getName(): string
{
return $this->name;
}

public function getNumber(): ?int
{
return $this->number;
}
}

I am now trying to achieve the same behavior using property hooks, but to me that seems to be a tricky task because property hooks do not support readonly properties. I came up with a solution, but this needs reflection to see if a property is really uninitialized. working with isset() would allow to overwrite properties that are initialized with null.

class ValueObject
{
use ImmutableSetter;

public function construct(
private(set) string $name {
set => $this->immutableSet(PROPERTY, $value);
},
private(set) ?int $number = null {
set => $this->immutableSet(PROPERTY, $value);
},
)
{
}
}

trait ImmutableSetter
{
protected function immutableSet(string $property, mixed $value): mixed
{
$reflectionProperty = new \ReflectionProperty(static::class, $property);
if ($reflectionProperty->isInitialized($this)) {
throw new \LogicException("ValueObject::{$property} is immutable.");
}

return $value;
}
}

even if this solution works and is somewhat reusable, I feel that it's not worth the effort and the overhead compared to the classic solution using readonly property with a getter method.

why did they make readonly properties incompatible with property hooks? is that a technical problem or just per design?


EDIT: okay I just realized why readonly does not work with property hooks: It's because even constrcutor property promotion uses the set hook :>

https://redd.it/1kxn4gc
@r_php
Best practices for PHP GraphQl response data extraction

So, as background, I am a retired Software Developer; but on older platforms (AS400, etc.), not the newer web oriented languages. I have decades of experience.

I have a website that runs a bunch of frontend HTML and PHP code. Down deep, one of my processes, runs a GraphQl query and gets back a ton of information (Arrays). that I'm using to validate form input and passing on to payment gateways. But I'm doing all the response data extraction via a bunch of string searches (strpos) and substring (substr) operations.

But I'm a bit of a perfectionist and like my code to do things properly and efficiently. I'm wanting to change my response data extractions to be more "best practice". I've seen mention of a foreach loop that appears to cycle through array to array to array processing (see JS foreach code snippet below) and ultimately appears to grab the product id. But I can't seem to get it to work for me. (I have a similar GraphQl schema to the below).

Using PHP, how can I get at that lowest level id, name and price so I can replace all my (current) string and substring code?

foreach($response->data->products->edges as $a){
// echo $a->node->id;

Schema looks like this:
products(id ----) {
id
noscript
edges {
node {
id
name
price
}
}
}

https://redd.it/1kxrcna
@r_php
Need help with xdebug in a multi developer environment.

I am a php web developer on a team of about 12 people. We all share a RHEL 9 server running PHP 8.2 and Apache. Each one of us has our own environment in /var/www/html/. We all use VSCode with the ssh-remote plugin to remotely develop on the server.

What we really lack is the ability to debug, so I had the server team install xdebug, which right now works for a single person using port 9003, but since we have multiple developers, I want us all to be able to use it.

ChatGPT and I cannot get this to work for web requests, but I can get it to work with noscripts.

I have these settings in php.ini
Zend_extension=“xdebug.so
Xdebug.mode = debug
xdebug.start_with_request = trigger
Xdebug.discover_client_host = true

I have a launch.json file with type:php, request:launch, port:9010 (I’m using this port since it’s available and I think we each need our own port), pathMappings: {“/var/www/html/myenv”: “${workspaceFolder}”}
I’m copying this from my work pc to an iPad, so bear with me on formatting.

What am I missing? I need to be able to have xdebug to be able to debug for all developers through VSCode. I do not have DBGp proxy enabled, I read that I don’t need it. I tried using the xdebug chrome extension, no luck there.
I configured the xdebug log and with the right commands can get it to debug a file I run in the CLI. But I cannot get web requests to show up in the logs, and my breakpoints are not being hit.
I have found very little information on xdebug with multiple developers on a single server in their own environments.

https://redd.it/1ky9fex
@r_php
Multi tenancy with single db or multiple db?

I have real estate management system i have for now 4 clients created separate project instances with separate db. I am really confused what multi tenancy approach should i use with single db or separate db for each client?


https://redd.it/1kyjbxp
@r_php
Is it okay to have two classes that extend from Illuminate\Foundation\Auth\User?

I'm currently working on a portfolio project, and I am creating a basic Electronic Health Records system (my last job was in the medical industry).

While the lead developer at my last job made some bad mistakes in the initial design, something I warmed up to was having both Patients and Users (Doctors, Nurses, etc) in their own tables, regardless of having some similar fields (first/last, login/password). I found that having these as separate entities vastly helped development and debugging.

I'm now using Laravel (and Jetstream/Livewire), and am wondering if creating a separate model/table for Patients and having it also extend Illuminate\Foundation\Auth\User could cause any potential issues. I'm only planning on using the built in auth system, and some kind of 2FA for HIPPA compliance. There is also a slight chance of creating a RESTful API down the road.

Are there any potential pitfalls I should be aware of?

I'll also add that I'm developing this with TDD via Pest.

https://redd.it/1kyj9vw
@r_php