Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [php]

Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.

-1
votes
0answers
34 views

Best Approach for PII and Databases [migrated]

PII, or Personally Identifiable Information, involves information that may include the following, among other data: First Name Last Name Email Address Phone (any of them) Billing Address Shipping ...
0
votes
1answer
45 views

PHP: simple class for storing read-only data structure, array alternative

I need to share some associative data between different parts of my application with two requirements: immutability (so read-only) safety against mispelling or unavailable index inside the data ...
2
votes
1answer
149 views
+50

How can I allow interaction between user-only modules & admin-only modules without polluting with privilege checks?

Important note: This is PHP (5.3+). PHP is stateless and everything you do dies when the request is over unless saved to a persistent storage, but if the answer provided gives me pseudo-code, I'd also ...
0
votes
1answer
60 views

RabbitMQ Consumer Architecture

I have been investigating using RabbitMQ for a publish/subscribe pattern across micro-services where aysnc calls are appropriate but I am having trouble understanding some concepts and could not find ...
0
votes
1answer
65 views

Which types of objects that are instantiated inside controller's methods should be injected into the controller instead?

Consider code below MyController //MyAction //MyHandler { public function processRequest() { // ... $myObject = new MyObjectClass(); $myObject->methodCall(); ...
0
votes
2answers
74 views

What to do when a class' method depends on another class' method to pass an array with a certain key?

To cut a long story short, assume I have a Register, a Provider and a Generator class. In my Register, I have the addItem method that allows me to add items to a collection. The Provider's job is to ...
2
votes
2answers
180 views

What is wrong with writing web applications in a way that merges repository layer with view and with controller in the same file?

is there anything wrong with writing code in a way that merges view, repository, controller in the same file? i.e. global $db; // or $db = DBSingleton::get_db_instance(); // or global $container; $...
1
vote
1answer
139 views

How does machine learning learn? [closed]

I'm new to Machine learning or Ai but I have been a developer for almost 10 years. I have a news aggregator application that grabs and save articles from news websites, And I have developed an ...
0
votes
1answer
54 views

Structuring PHP classes that need to return multiple objects

I am trying to plan out php class structure for an order processing project. I've used classes before but I'm still not an expert on OOP yet. I've been searching for hours and can't seem to find the ...
0
votes
0answers
29 views

Wrapper class organization

I have Auth class which I am calling at one place in the code: $this->auth = new Auth($this->options); Now, the Options is the class containing things like host, port, username, pass... and is ...
0
votes
4answers
117 views

Could you please recommend an approach on converting non-unique field to a unique field?

On our prod db we have two tables: companies invoices Relationship: A company has many invoices An invoice belong to a company The invoices table contains duplicate invoice_number for each company. ...
0
votes
2answers
49 views

PHP class inheritance in variable depths across systems

I have a project where I develop a software which consists of a CORE which is in a separate project, developed separately, and a CLIENT which's base is the CORE but adds to the functionality with ...
0
votes
3answers
98 views

Can I make other developers aware that they can define certain functions for extra-functionality even if they're not required?

The language is PHP. I have the certain, in my opinion, code smell, it doesn't feel right: In my controller class that ingests objects of the same type (interface, it's ViewBlockInterface), I check if ...
4
votes
3answers
355 views

What to do when interfaces force me into violating the single-responsibility principle?

(The code I'd have to post is huge, I'll resume to just function names) I'm currently faced with the following issue on my project: I have a "each module from this framework can have a small view ...
2
votes
1answer
64 views

How to implement acquaintance and aggregate as described by the Gang of Four

Is the following implementation in PHP correct? I focused on what they say about the lifetime of dependencies: “Aggregation implies that an aggregate object and its owner have identical lifetimes.“ ...
0
votes
1answer
95 views

Integrate react app with php app

I have an old php web application, with very bad code. While a lot of it just has html and ajax calls in the, the wrapper is still php. I want to develop the new modules in react, and slowly replace ...
3
votes
3answers
188 views

A better way to generate plaintext content

I'm generating plaintext emails with heavily personalized content: depending on various factors, sections or sentences need to be inserted, left out or phrased differently and placeholders need to be ...
0
votes
3answers
197 views

Separate Function or Same Function for similar functionality (SRP vs DRY)

I'm trying to decide the best course of action based on two design principles that seem to be conflicting with each other: "a function should only do one thing" (SRP) and "don't repeat yourself" (DRY)....
0
votes
0answers
58 views

Allowing a user on one page to be able to cause an event on another

I would like to allow a set of users to be able to submit a form on one page, and then it would cause an event to trigger on another page. For example: Submit Page: Includes the form, the user ...
1
vote
3answers
160 views

URL friendly id from DDD entity id

I am currently learning DDD and having a hard time wrapping my head about how to implements URL friendly ids for a web application. From my knowledge, in DDD it is common practice to use UUID as ...
2
votes
1answer
109 views

PHP - Dynamically apply parsing rules to text, and save to dynamic fields

OK, so I have been at this problem for the last few days, and I must admit - I am stuck. I am trying to make a web application, where users can upload documents or send inbound e-mails. Each ...
1
vote
1answer
122 views

PHP - Designing a rule based parsing engine

Dynamically apply methods/"rules" to documents I hope someone here can help me/guide me in the right direction. I am currently creating a web application, where users can import a text file, and then ...
1
vote
1answer
145 views

User class: How do I handle different user “subjects” and still keep my single responsability principal?

I have a User class, this class handles things like: login (UserAuthenticateModel) Handle user sessions: user login tokens, fetching user from session if set in session, ect' (UserSessionsModel) ...
1
vote
1answer
73 views

Data is in database or get from API, where should API request code goes?

For me, the data I want to retrieve may be in database for which I can use properties of model and also relationships, but if the record is not a property and no relationship exists for that ...
0
votes
0answers
26 views

Creating the perfect self populating CDN, serving static optimized content from cookieless domain

I am building my own CDN in PHP and I am thinking that having Apache serving static files must be the optimal strategy, so a well crafted .htaccess file handling all headers correctly sounds like the ...
3
votes
4answers
236 views

Is a cookie hash that matches with file hash safe?

I've made a simple login form. It's made very generic to be used for any project. Now I wonder if the security is good enough and if my approach is safe. On success When successfully logged in I do ...
0
votes
2answers
78 views

Website Multi Languuage [closed]

I have one website and the website are now in HTML, that actually is structured: domain.com = English domain.com/es = Spanish domain.com/de = Germany I copied the HTML of English page to Spanish ...
2
votes
0answers
42 views

How to let users specify their own logical conditions (PHP / Laravel)

I am currently trying to create a web application, that saves inbound emails. I have figured out how to save the incoming emails into my database, and I have all the email information available (...
1
vote
1answer
146 views

Building a MVC Framework: Should I get an instance of Database, or should I extend with a “general” model class that already has an instance of DB

I am trying to get a database instance via any model-class that uses the database. This is ideal in my opinion: class UserAuthenticator { private $db; private $customer; public ...
0
votes
0answers
55 views

Apply Value Object (Stringly Typed) in PHP

What is the best way to prevent wrong states in an object? This is the source of my question. Basically my curiosity started with the intention of not letting a class exist with wrong values. Prevent ...
-2
votes
1answer
37 views

over come HTTP client time out issue

I have an api end point which receives some parameters and process them returns a csv file. But the processing time may take more than 15 seconds. My server has build in timeout and some client ...
0
votes
4answers
130 views

Is there a pattern or best practice for returning dynamically typed data?

I have a method that returns the percentage change of a data in a certain period. After calling that method, i need to know if in the current period the data increased, decreased or is the same when ...
1
vote
2answers
100 views

Should you “rebrand” the exception of the library you're using?

Say your making a library Foo that depends on a 3rd-party library Bar. Bar throws a custom exception \OtherVendor\Bar\CustomException. Is it recommended to just throw that exact exception to your ...
0
votes
1answer
79 views

Is singleton use acceptable for static single responsibility?

I have been reading into possible design patterns and have found the use of singletons always referred to as an anti-pattern. I am currently using a singleton for the sole purpose of gathering ...
1
vote
2answers
63 views

Integration Testing: Should a test check every validation?

I am somewhat new to writing tests and I want to build that habit into my workflow. So for example I might write a test that a user can create a blog post however I'm not sure on how to do that ...
0
votes
1answer
78 views

Database abstraction layer

I'm currently developing an SaaS application in PHP, with Laravel, using its own DB class. Let's pretend we've got 2 classes under 2 namespaces, plus Laravel's own DB - so Illuminate\Support\Facades\...
0
votes
0answers
76 views

Role Based Access Control on OOP how do you map Permission of Role to Entity?

I've been trying to wrap my mind around this RBAC system. The goal is with a static method from a class, I can get the current user/actor, then check if he has capability to do something for specific ...
-2
votes
1answer
93 views

PHP MVC - which approach is the right one

Next semester we'll learn the mvc pattern in web development but since it looks pretty interesting to me i decided to learn it now but...there is a problem. Surfing trough the pages i found two ...
0
votes
0answers
53 views

Getting into situations that requires mixin while building classes. How should I correct my class design?

I have the following classes for to solve a particular problem related to HTTP responses. Problem is for class ServerSentEventStreamResponseService I am in a situation where I need mixin because I ...
0
votes
1answer
47 views

Considerations for delegating long running to CLI from PHP/Apache

I'm working on a web project that executes CLI commands to perform running tasks to spare users from having to wait since PHP/Apache combo cannot (to my understanding) create a separate process for ...
2
votes
0answers
47 views

Restructuring PHP application classes

I'm trying to modernize a very old PHP application for a customer to keep its code base up with modern coding standards. I am permitted to restructure things a bit, but dumping the entire app and ...
0
votes
1answer
32 views

Updating a distributed backend and keep track of compatible releases for Electron app + Webserver (PHP + MySQL )

Currently i'm working on a small platform with a simple client-server model and will soon go in a closed beta with a launching customer. In essence it's an Electron application which is mostly used ...
0
votes
0answers
95 views

Which architectural patterns should I use for a decoupled notification system?

Background The application I work on use a command bus to handle events (REST API HTTP requests, commande line interface). This bus is built using the well known league/tactician package. Feature to ...
-4
votes
1answer
75 views

Public var vs protected var and get function [closed]

I've noticed this style of code a lot in frameworks like Symfony and Magento 2 (which is based on Symfony): <?php class Foo { protected $foo; # construct function - not ...
2
votes
5answers
252 views

How do you force developers to define dependencies/arguments if it's bad to put the constructor function in the interface?

I just started reading more about OOP and its design patterns and is confused with this conceptual question. I am too new that I am having second thought that the proper title should be, "when is it ...
0
votes
1answer
70 views

Folder structure for child classes

I have a user feature. user feature also has other subfeatures user application details and user contact information. Usually, because application details and contact information are part of user ...
-1
votes
2answers
62 views

Design Pattern to wrap a series of step

I'm already posting this question on StackOverflow, but thought that asking it in different communities might give me different insight. So here's the repost of the question: Hello, I'm having a ...
0
votes
1answer
56 views

Using the adapter design pattern for a news application microservice

I am currently developing the backend for a news application, which fetches news from various aggregators (e.g. Feedly). I thought this qualified as a good use case for the adapter design pattern, so ...
-4
votes
2answers
98 views

should i create db functions in MySql rather than Php code?

I have a MySQL database and I am working with Core PHP. What is the best practice in terms of accessing the database? Should I create functions in MySQL and access them in my PHP-code OR write ...
1
vote
1answer
94 views

Secure Admin-pages-only login without HTTPS

I'm adding admin dashboard to a website that doesn't use HTTPS. For now only that (admin) section requires user authentication. If I use encrypted + salted password and check the client IP address to ...