Tag Info

Hot answers tagged

6

Create alias references for the Location and Address objects to shorten the assignments. $loc = $api_object->Organisation->Location; $main = $db_object->MainAddress; $loc[0]->AddressLine1 = $main->address_line_1; $loc[0]->AddressLine2 = $main->address_line_2;


4

There isn't anything significantly wrong with the first piece of code. Though having more than half a dozen dependencies may indicate a violation of the SRP, there is nothing inherently wrong with having a large constructor. In fact, I would much prefer seeing a constructor with a large number of arguments than a method. Constructors are for getting our ...


4

As an outsider looking at this code, it is not clear how the "hidden dependencies" get created to begin with. What if there is no "db" dependency registered? Does it throw an exception, return null? If my class doesn't get a "db" dependency, how bad is that? Many times people lean towards this pattern when there are too many dependencies to pass in the ...


4

You've got a situation where an exception occurs for some reason or another. There's really no point going on and you need to start bailing out and rendering the corresponding web error page (this is a web application after all). Now, to present some information to the end user, you need to somehow get some data to that error page. And to that extent, an ...


3

It's not a PHP specific problem. Whenever you want to share memory with multiple processes (PHP scripts terminate after they finish), use Shared Memory. In PHP, shm_attach() should get you started. Implementing cache on top of shm should be straight forward.


3

Ideally, you want both unit tests (which test individual functions) and integration tests (which test all the functions together), not just one or the other. You will also need a way to mock out the web service you're calling so that these tests don't depend on it. To directly address a few of the sub-questions: So is correct to create a big test that ...


3

The description of the range is poor. However, there is a clearly defined in the zoning codes. From section 11-122 of Zoning Resolution (Web Version) (the linked pdf) R1-1 Single-Family Detached Residence District R1-2 Single-Family Detached Residence District R1-2A Single-Family Detached Residence District R2 Single-Family Detached Residence ...


3

If you're looking for 'the correct way' to marry Object Oriented code with Relational Database persistence, you're going to be sorely disappointed. There is no single 'correct way', only a range of options. Some would recommend separating your concerns (as AvetisG has suggested in his answer), by putting business logic in one class and persistence logic in ...


3

The problem should be addressed by separating concerns Here is what I mean. The reason why you have a bad feeling about adding the getAllUsers() to the User class is because it is too much responsibility for that class. This could convolute things down the line - especially when trying to test things. My suggesting would be to rethink the way you are ...


2

First, lets start out with "there is no on line provider that allows per brach access control lists as part of its base service." It doesn't exist as such. What does exist, is the ability to do add commit hooks. For example, in git you could put a pre-receive hook on the server. This hook would check to see if the person doing the commit is one of the ...


2

Since you said, that you assume that there are no curves, the graph itself would probably look like a stock development. So I would try a vector calculation approach. With the data you gave in your example you would get 3 vectors defined by two points. (To generalize it, you would get one vector less then you got points.) In your example: Vector1: ...


2

I understand this post is year old, which is ironically the reason I am posting this response. First off, some of the people who answered this question are right. You're never really going to find a PHP Framework that come "MVC Ready" right out of the box...necessarily. Seeing as the framework is supposed to be a foundation where Dev's can build upon it, ...


2

tl;dr answer: DON'T. PHP supports parameterised queries; make the most of their ability both to handle all the nasty implementation details of converting dates between PHP and SQL forms, because it will be quicker to do so and far more solidly tested than rolling your own. In addition, you automatically get protection from SQL injection attacks that you ...


2

First of all, with your question details: Now I want to add optional description and dependencies methods. If you want an optional method, then you should not go for interface, because as per interface rules, you MUST need to define methods in implementation class. See PHP interface. So according to that rule, your first solution will not work because ...


2

The real question you would have to ask is, "Why should I use an MVC pattern". The reasons for using such a pattern can only be explained when one has an understanding of principles that programmers want to adhere to for a number of reasons, but maybe the most important one: Seperation of concerns The value of separation of concerns is simplifying ...


2

Why reinvent the wheel? Try ELO rating system - it was developed for exactly this purpose, and is best known for being used to rate chess players, although not exclusively. And it stood the test of time, to be sure. As for calculating the probability that player (or team) A defeats B, look under ...


2

Why is the tight coupling an issue? If I create a class containing two integer fields or properties, it is tightly coupled to the implementation of integers. Is this a problem? Only if you need to change the integer to a different type, selecting that type at run time. The premise behind the question (tight coupling is a problem) seems flawed. We can always ...


2

How is your code easier than the first one? What would Magento constructor look in your example? It would take the same parameters as the actual constructor from the first piece of code, and the only difference would be that instead of one class, you now have two classes. Refactoring should improve code, not move the difficult part to a different class. ...


2

The easiest way I can think of to get access to a chunk of memory from php would be via tmpfs. Then you write a hash table implementation (+your cache logic) in terms of operations on file handles. This might be fun as an exercise but if you do this on someone else's dime you are not doing your job properly imo.


1

The first approach you mentioned is absolutely perfect and there is no need for code refactoring. Dependency Injection is very useful for writing test cases on your class. Because you can easily mock the injected class functionality while you are writing test cases as per your need. The second approach you mentioned is a wrong one. Because, you are passing ...


1

if any of the methods fails, there is really no point in calling subsequent methods. How should I address those possible method failures? Throw an exception. Should the Carousel class be 'injected' into my class before it is used? Yes, if there is more than one implementation of Carousel (including the possibility of a mock object for unit testing ...


1

This feels like a "service" class or an implementation of the "unit of work" pattern would be beneficial. I'm leaning towards Unit of Work here. You can define multiple "unit of work" classes in a hierarchy to break up the updates. Plus you can define additional classes for updating the $db_object with values from the $api_object. While this adds ...


1

Along with Robert Harvey's advice, rather than 'setting' an existing API object's properties from an instance of a DB Object directly where you need it to happen, why not just 'create' a brand new API object using a factory that uses your DB object as a template? class ApiObjectFactory { public static function createFromDbObject($dbObject, ...


1

Your single-line HTML snippet will work fine. Improperly written browsers could conceivably choke on one-liners that exceed ridiculous maximum lengths, but in practice something like your snippet should not pose any problem. Of course, since you work in PHP anyway, my preferred way of handling redirections would be something like: <?php header("HTTP/1.1 ...


1

Should I separate and create a PHP file for insert and a PHP file to get results from the database? First, you may separate your data access from the business logic by moving data access code to a data access layer. For instance, if the select boxes are populated with the list of countries, then you'll have to call: $this->db->listCountries(); ...


1

Always go for separate interfaces in this case. As the task part is mandatory and the second part is optional. Interface always forces to override all the methods mentioned in it. Now think if you don't want to use the optional part. Still you will have to override it. Even if it doesn't do anything.


1

Conceptually, it would be ideal to have a centralized API for each "system" (But not the same for all systems). I use the term system, and quoted, because you may have many apps in a single system, as well as an app that works with more than one system. A nice example would be a WebApp and a Mobile Application, being two diferent "applications" that work ...


1

The question is a little unclear, but it sounds like you need to revisit your class design. My analysis is that you are selling Products which belong to a Category and are stored in an Inventory (in your case a flat-file data store). You will also need a ProductStatus class to hold stuff queried from the inventory e.g. Number in stock, isCurrentProduct() ...


1

I'd go with the function. Like you said, the first option introduces too much coupling. Option two looks okay but since your class will probably don't have to maintain state I'd go with option three. If in doubt, go with the easy/dumb solution ;).


1

You can write a shell script to do this. Run app1 and redirect the stdout and stderr to a file. Check the exit code, if fail, exit. Same as above. for running app3 and app4 parallely, you can run it in background. To capture the output and return codes, you should take a look into bash coproc (http://wiki.bash-hackers.org/syntax/keywords/coproc). Redirect ...



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