Tag Info

New answers tagged

1

I still think it makes sense to stick to phpDoc to document PHP code. It is the standard recommended by the php PSR project. It is also generalized into the annotations concept, as it is used for instance in Doctrine. Another argument for phpDoc is that Javascript and many other languages have it's analoguos commenting system. After much time spent to try ...


3

Here are some points you should take in consideration: Readability: long regular expressions are difficult to understand. Use comments (and eventually break one long expression into several small ones, if possible) to make it easier to read. At the same time, the piece of PHP code in your question can (and should) be refactored to make it more readable. ...


2

The abstract Controller class can't create the right <concrete class>Domain classes, because it doesn't know which concrete class it belongs to and which Domain and View classes it should be associated with. What you can do is pass in the Domain and View classes from the derived class's constructor. abstract class Controller { private $domain; ...


0

I would approach this by having a top level UserService that doesn't care what type of user it's dealing with. If it gets a request for a user by email, it can look up on the database which type of user is correct and delegate the request to the correct service. This may sound a little inefficient, but used with an appropriate query caching later it's ...


13

Note: This is written from a highly opinionated stance. Long ago, when the web was young, you wrote a web app in perl. That was really it. That was your only choice (unless you really liked working with strings in C). (And yes, I'm glossing over great swaths of ASP and the like... I'd rather forget those days.) There were great and large applications of ...


2

The issue you are facing IMHO is a growing amount of technical debt. While usually attributed to poor design, I attribute to overall poor software engineering practices. The problem is, once you've accumulated some, you'll have to pour a bunch of resources in to get out of it before you start seeing major improvements. But in the end, I promise the work will ...


-2

I would say, it depends on how I design my view. If I need to load relatively less data like in authentication page I say no to Ajax. But if I design my view in such a way it keeps growing when user scrolls down Ajax makes sense. For example: In a blog when user scrolls down from top most post , the previous posts will be loaded.


2

Create a table which will store information about notifications: TABLE notifications event_id user_id datetime // date and time when notification must be sent Every time someone joins some event, you should insert a new row in the notifications table. To notify users, you need script which will perform a mysql query like: SELECT * FROM ...


3

Should we use another way for sharing data between these three classes? No, that is not the point of what Fowler is talking about. The usage of a DTO is probably fine (Fowler himself recommends it, especially in a remote scenario). The point is that during refactoring, such a DTO might become a better place for operations which work exclusively on the ...


1

The first solution you have proposed is an excellent solution, as it namespaces your code properly and means that your code is in the correct structure should you want to shared your code through a package manager (like packagist) later on. If, at some point, you intend to share you code to other developers via something like packagist, you would do the ...


4

Object-oriented design + Dependency Injection (DI) You should consider using object-oriented design together with Dependency Injection container. I recommend Symfony specifically because it has a great DI container component. Instead of having a bunch of DB-related functions, consider grouping them into classes which deal with particular types of domain ...


0

there is also APC, Alternative PHP Cache, it is common in shared hosting php servers. It has also the ability to define a timeout for each variable. The syntax is pretty simple. <?php if (apc_exists($s_lang)) { // array in ram $l = apc_fetch($s_lang); } else { //fetch the resource here. example: require_once(__DIR__ . ...


0

You should also take a look at X10, which has been around at least 25 years to my knowledge. Back in the day I used to just power deceives on and off, but it has grown to be much more sophisticated since. X10 is a protocol for communication among electronic devices used for home automation (domotics). It primarily uses power line wiring for signaling ...


1

Rather than trying to modify the firmware of devices, and alternative is to harness what is already in place. As you say, a small single-board computer is a good solution. Try a Google search on Arduino. These boards are cheap, and are designed to control lots of IO lines. Programming in C or C++ is the norm and you are working with bare metal - there is no ...


1

This is a quick article about the relationship between APIs and hardware. Generally, if you are accessing hardware directly, you would generally use a C or C++ driver. You might raise the question: how do all the other languages access the hardware? They utilize the C or C++ compiled driver. EDIT: One of the commenters provided a list of high-level ...


0

I have 1 query with multiple pages. There are filtering parameters on the left of the page which $_POSTs on submission. That is your problem right there. A query should be a GET according to the HTTP verbs, and using a GET would make it easily possible to simply pass the search query along from page to page (this is how every single search engine does ...


1

There are two major drawbacks to doing it this way: Your site will break for any user who has cookies disabled. While this is not a common configuration, it does happen sometimes. Users who try to open multiple tabs on your site may find their navigation going haywire. I tend to avoid it for these reasons, but if it is the only realistic way (I've never ...


0

The two methods are correct but if you want to dinamically change the content of subcategories either you reload twice the page or you use ajax. Without ajax you need to reload the page twice 1 for the selection of the parent category and 2 for the selection of the child category. The server has to know which was the parent category to return the set of ...


0

This is how you are tracked without cookies via the browser fingerprint. https://panopticlick.eff.org/index.php?action=log&js=yes Idea: Each browser has a unique fingerprint if you get enough features ip address installed fonts javascript yes/no adblock yes/no accepted headers is some stuff cached? java screen size If you get 20 bits out of the ...


0

If you are concerned about load you could use redis or in-memory storage, and them periodically offload the results, see: Python example, could be adapted to php Uses Redis bitmaps to store the counts


1

All I can see above is just an application of the strategy pattern. How much you have to extend this code to make this a real "plugin architecture" is debatable, but IMHO the central point is to have the deployment of new billing system implementations decoupled from the deployment of the main system. Ideally, you, your team, or a third party can deliver ...


1

I am not a PHP expert, but I can read the code. When I see this code // Probably correct $mapper = new Mapper(new MapA()); print_r($mapper->parseData(['backField1' => 'foo1', 'backField2' => 'bar1'])); Then I think to myself, why do I need to instantiate a Mapper with MapA. I would want to have 1 class that both holds the data and knows how to ...


2

What you have is a combined date and time, formatted according to the international standard ISO 8601. The T is just a separator between the date and time parts (you could read it as the t for time). The Z is a timezone indicator and signifies that the time is in the UTC (or zero) timezone. The date is always formatted as year-month-day and the time uses a ...


1

firstly for multiple classes with the same name, I would suggest that you use namespaces to clear out what class in which namespace is supposed to handle it. most frameworks error handlers can be overwritten to achieve custom error handling , I'm using Yii and at least that is supporting it. and also you can use the old frameworks working parts and include ...


2

Your model is casual security, so you might as well just flip a coin. Not to be sarcastic, but if you store your keys in code and are sharing the key across all users of your app, and your goal is just to obscure the data from casual tampering, then it really doesn't matter. Pick a symmetric cipher (AES-128 block cipher for example) and be done. It is ...


-1

Do you need a separate step? It's often faster to read each line, clean it and insert it into your CMS. If you have a lot of cleaning and processing, you might want to look at kettle from pentaho, it handle Extraction, Transformation, and Loading (ETL) and could help you (beware, takes a while to master)



Top 50 recent answers are included