Tag Info

Hot answers tagged

11

Comma is a separator between parameters in the parameter list. Comma is part of the parameter lists. Optional parameters are usually specified inside square brackets in documentation like so: [, int $case = CASE_LOWER]. Comma is added to specify that if you were to use the second optional parameter, you must have a comma separator as well. The fact that ...


6

Let's immediately get the Turing-completeness disclaimer out of the way and say any language can probably approximate any runtime feature of any other language. Good? Good. The main difference between the Node.js approach and a Python threaded-server (or a typical Java HTTP server implementation) is that Node.js is single threaded while the latter two are ...


4

Starting with the last question, documenting the framework requirements is a must, but having the version check will be useful for those foolish enough not to read the documentation. Having the minimum version as a configurable option doesn't make complete sense, as the minimum version is an intrinsic property of the code itself, not something external to ...


4

I have encountered this issue several times and have found what I think is the simplest solution. Since your user can edit (personal/account?) information, I assume you have some kind of authentication system up and running. If you use sessions to keep track of recognized clients you can store the user's ID inside it. Then you can fetch the ID from the ...


4

You are over-using SRP. Let's take a look at mappingConcern's creation-and-initialization version: public function mappingConcern($data) { $parameters = $data; $product = new Product($parameters); return $product; } $parameters is the same as $data, and $product is returned immediately, so it can be translated to: public function ...


3

While there are no hard rules about the size of a controller, 5000 lines is clearly beyond any reasonable size for a hand-coded class. Chances are this class is violating the Single Responsibility Principle (SRP) and therefore is flawed. You most likely have several methods in there that can logically be grouped together. See if you can't extract methods off ...


3

Why create a whole other classes to handle those responsibilities? Because when you're doing Object Oriented Programming, your focus should be on the objects. They are your unit of work for making the design and providing abstraction. And most importantly, they are your unit of reuse. By letting them change for different reasons, you're forcing people ...


2

Can I have an object called Algorithm, that is essentially a bundle of methods that loads Products, Motors, combines them, does computations on them, sets up various flags, etc? Or is there a better design? The Strategy Software Design Pattern seems to match the description of your post: https://en.wikipedia.org/wiki/Strategy_pattern This Pattern allows a ...


2

I would improve on OOP part a bit. Provide better naming: You can to change Algorithm to something more specific like RelatedProductsService. Then, expose a method: getrelatedProducts($options) Separate Your responsibilities: You also want to avoid just passing POST along the class into it's children. That is a code smell and creates unnecessary ...


2

You shouldn't catch the PDOException at all. Now, you should have some sort of last resort exception handler that catches all exceptions and logs them. PDOExceptions should be caught there. But you shouldn't catch them anywhere else. In my understanding, PDOException indicates either that something has gone very wrong with the connection to the database, ...


2

$this->$data['id'] = $db->insertANewProduct($data); I think is a bad practice, because breaks de Single Responsibility Principle, the product class knows it's been persisted. You are loosing what you win with the repository pattern. If you want to do that another option (less OO) is Active Record. I would choose the option 1 public function ...


2

Just use an URL with some query parameters, like <a href="user/5?checksum=12345">Edit</a> Of course the checksum is computed, perhaps using some session cookie, and your server code has something to validate it. So if your user is abusing the system by editing the URL (e.g. replacing user/5 by user/567) the checksum should no more be valid. ...


2

As designed with roles being a one to one relationship with users, my personal preference would be to ditch the lookup table for roles entirely and go with an enum data type in the users table. Internally in MySql it's going to be stored in a similar way, so it will not take more space. But it will return the string representation in the results making it ...


1

Your approach is far different from that of most PHP applications does, obviously a template engine binds some logic in views, most programmers prefer writing this logic in PHP itself. Limiting PHP to create services/ API s to only manipulate Data is a good idea, indeed. You may consider http://backbonejs.org/. I believe you could use it to write all ...


1

You can: Use polling However, think about sending a request every 10 seconds. By using your suggested approach, you are keeping a long connection to the server, which is in turn keeping a busy process/thread. If this is used only by you, it's fine. If it's meant to be used by many users, it's a huge waste of resources, since the server will be busy doing ...


1

First of all, I don't think Composer is trying too hard to be a PHP version of NPM - there may be similarities, but differences are to be expected. It may not be the best way to understand it to think of the tool as NPM, Maven, Rake or whatever, but translated into PHP. Secondly, understand that Composer solves 'problem' of autoloading in PHP. Having two ...


1

Lets assume index.php as your home page. I can assume that your controller might work using a action parameter appended to the URL or based on request parameter set. index.php?search would takes the controller to execute search logic and there you get all post data of search criteria. and loads products based on a query mapped with data keywords entered by ...


1

If I'm understanding you correctly, you are providing a list of items with 2 (or more) categories and you want to display them sorted or separated in some way. The options are multiple requests, one for each selected category. Or a single request allowing the client to specify multiple categories. If that's in any way close to the correct understanding, ...


1

It should be absolutely fine. You simply are not assigning the object to any variable and gets disposed of automatically. BUT, I would look at larger scope issues here: If you don't need an object, class(or method I guess in PHP) should be static instead. // Static invocation myClass::myMethod();


1

A Factory or Factory method is a way of creating objects without having the calling method be aware of the specific class of object that is being created or the dependencies it has. It takes away the complexity of instantiating objects for which (some of) the properties are not known at code-time but can only be known at run-time. Your Entity Translator ...


1

What you probably want to do here is use a repository... This would have your querying methods directly related to your Object and would use and instance of the DB as part of its constructor: $repo = new MovieRepository($db); $movies = $repo->findAll(); And or writing you might have: $repo = new MovieRepository($db); $movie = $repo->findById($id); ...


1

I would argue its impossible to handle all exceptions the same way. I think you should let it propagate back to the calling code as it ultimately knows how it should handle the exceptional situation. Just to think of a (maybe weird) example. Imagine you have an blog. An each hour you query the database for new articles. But luck isn't with you and your ...


1

Your application probably have different actions with different access levels, for example an admin will probably be allowed more things than a simple user. So you better build some data-matrix summarizing user(-roles) access-rights and check brefore treating any request if the current logged-in user (or even unlogged Guest if you happen to have such a ...


1

I think as per the PRG pattern if there is a refresh after step2 there won't be an issue as the client(browser) will receive and use the redirect url. The problem happens when the user refreshes before step 2 is completed(before sending the redirect url)!


1

Totally depends on your application. I've seen a few commercial solutions: https://prerender.io middleware, which works with Zend Framework2. It's free for under 250 "pages" and works if 7-day caching is acceptable. Also, check out Brombone (sorry not enough rep to post another link...) If you want to go manual, you'll need to do a few things (details ...


1

Since a data mapper should have a single responsibility, it should only map the results of the query to an object or object(s) and return that back to the caller. In your case we have: Product Motor So, I think one would definately have mappers for those objects defined. I beleive your choices for mapping product and motors are: Composition. ...


1

Typically the right place for a file exchange folder would be outside of the webroot where both web applications have access to. So it's anywhere, except where other files reside. Files will generally be FTP'ed or SFTP'ed (FTP over SSH) to the server, or share the same folder on the host if they are served from the same machine (actual machine or VM). Make ...


1

The answer depends on the responsibilities of your wrapping class. If all it does is encapsulate your connection settings for convenience, then simply letting PDOException pass through is preferable. If your wrapper has more responsibilities such as encapsulating certain queries or connection pooling, you may want to develop an exception or two for this ...


1

Rule of thumb is: If the input comes from anywhere else than from the code itself, the data provided is to be considered 'tainted'. You will have to make sure the value is what you expect and would not mess up your SQL statement (injection). Though I question why you're not using/utilizing PDO and use markers in your statement so these things are handled ...


1

Composite often goes hand in hand with Builder pattern to address exactly the problem you have mentioned here. You can create a separate class, call it PageBuilder (or whatever suits your fancy) and move all the building logic into that class. Although I don't know the internals of your code but considering a very generic composite/builder duo here is some ...



Only top voted, non community-wiki answers of a minimum length are eligible