New answers tagged

0

It is all a bit of semantics. A service would be a helper class, or in a sense a helper class would be a service. In terms of Laravel. Creating a service (which is a specific thing) would help code reuse and make testing easier. It is well worth getting over the hump of learning how to do. The number of services you need tends to grow as do the ...


-1

If you know WordPress like you mentioned and don't want to learn PHP, why not fire up a WordPress install and use a plugin like Ultimate Member This plugin does the email verification only in the premium version, I think. In fact Googling "WordPress plugin register users" will come up with loads and the official ones have a useful users' rating on the page. ...


-1

Php is not a programming language. So writing strongly-typed is not possible if your language doesn't have a real type system. But you can help your IDE like PHP-Storm to do the trick you want... Your view definition: interface mySimpleView { public function getTitle(); } Your template file: <?php /** * @var $this mySimpleView <== Your IDE ...


0

I agree with Robert Harvey that you could add some more context with this question, specifically how much are you going to reuse this, what do you intend from learning from building such a CMS templating system etc. In regards to your specific questions: Yes of course it increases data size, but this is not a performance problem. As you need to be using a ...


1

I'm going to answer my own question after a day of research. In the end this ended up looking more towards cron jobs which support MVC web applications (which isn't exactly the same as my original question but yielded some interesting information none-the-less). Anyway, here's what I found: Q. The concept of routing all requests to one file is a little ...


10

There are some posibilites, how to mock static methods in PHP, the best solution I have used is the AspectMock library, which can be pulled through composer (how to mock static methods is quite understandable from the documentation). However, it's a last-minute fix for a problem which should be fixed in a different way. If you still want to unit test the ...


4

First, I would suggest to split this up into separate methods: public function validate($value, Constraint $constraint) { $totalCount = QueryTotal($value); ShowMessageWhenTotalExceedsMaximum($totalCount,$constraint); } private function QueryTotal($value) { $searchEntity = EmailAlertToSearchAdapter::adapt($value); $queryBuilder = ...


0

OAuth2 defines a grant flow called client credentials grant. This allows an application to authenticate as itself and acquire an access token from the authorization server. It requires the client to register itself (get a client id) and create a client secret. It seems that the API you're using does support this.


-1

There are more than 1000 way except MVC some of them are similar to MVC and some totally different for example : Model-Template-View - MTV Model–view–presenter - MVP Hierarchical model–view–controller HMVC Model View ViewModel- MVVM etc


1

First off, even though PHP is class case insensitive I would rewrite EXCEPTION to Exception as it's easier to read. Also, you're missing a few semi colons. I would fix those few things first! I'm not very familiar with the the Laravel database classes, but I assume you're using Eloquent? If so you may be able to catch the \Illuminate\Database\QueryException ...


-2

If you can adapt your parser/crawler to click through to each RSS/Atom element's article, most news sources implement some form of structured data for their articles to better facilitate SEO and social network requirements like Facebook's Open Graph. For example, if you look at any article on CNN, you'll find two <meta> tags: <meta content="cannes ...


0

I think the easiest way to implement this behavior would be to cache the ajax responses somewhere. That way you wouldn't have to change any of the react/flux code (or any framework at all). When you click the back button, the API would return a cached result instead of making a new request, and the data would be available instantly. Here is a naïve ...


2

There's no single explicit approach here for making "perfect" mail templates, as everything depends on the complexity of your templates and scalability you want to achieve. Through my experience, I've been working with different approaches, and all of them served well for the specific project needs. It's matter of personal taste and skill, one have to find ...


2

Neither approach is functionally better: the both do the job (except the self keyword would need to go in your namespace-based example). So the difference lies essentially in clarity and maintainability. If your intention is that none of these functions have any shared state whatsoever, I think that clearest approach is the one that explicitly forbids it: ...


-2

That's exactly what I've done with similar projects, created a wrapper function around phpmailer. I then have an email template file, eg: <html> <body> <h1>{SUBJECT}</h1> {BODY} </body> </html> I then have a function which I call with the relevant data which loads the templates and does text replacements.


-1

Have you tried executing other PHP file? I mean if you have successfully login using first captcha, u may want to try to execute other PHP file that work on the same site. Before that, you may want to write any related data on text file using fwrite() function, for the use of your other PHP file.


1

This is the question as I understand it: Is there a superior way to classify files that contain code? Here are two example classifications. Not really. In my experience, both approaches are valid. The "better approach" depends on the codebase, the organization and possibly personal preference. Smaller/newer projects start off and benefit from the first ...


1

Actually this is matter of cohesion. From wikipedia: In computer programming, cohesion refers to the degree to which the elements of a module belong together. You can check this article about cohesion: https://en.wikipedia.org/wiki/Cohesion_%28computer_science%29 For me the modular approach, as you call it is representation of functional cohesion, ...


1

A good rule is to avoid having objects that are in a illegal state. Therefore creating objects based on data from the database that is illegal (or indeed has become illegal because you have changed the rules) without anyone knowing about it would be bad. It would of course also be bad if noone were able to start your system because one record somewhere ...


0

If data is coming out of your database, then you can [usually] assume that it's correct. It wil have gone through a lot of checking to make it through in the first place, so re-checking it on the way out again is [usually] overkill. Note the peppering of 'usually's in the above. Not all of the data that gets into your database does so through ...


3

I usually keep tests and src completely independent, and not nested under each other. Sources and test sources are typically defined like that. In an application, I usually have following: module /Application ... /src /Form Form.php // Application\Form\Form /test /unit ...


3

Technically, there is no quicker or slower alternative: it's the same request to the same resource, and the processing and sending of the image would probably take much more time than the displaying on client side. The only difference is the perception by the user, with a major difference between <img> and background-image. If <img> doesn't ...


1

The examples shown is correct, but Zend\Form is not exactly what you want to use in your controllers. I'm talking about Exhibit A, where it shows how much code to create, populate and style a form with two elements. It is tedious to create forms that way. To avoid turning the controller into a form factory, you need to create a factory that will create the ...


1

The question is already a bit aged, but maybe someone still stumbles upon it. Most of the mvc-based PHP frameworks offer a feature called scaffolding. With this feature you can easily create simple masks for CRUD operations. Instead of ids ususally a display-field is used for defining relations. I often use CakePHP to achieve what you describe, but it ...


0

base64_encode is used to encode binary data including null bytes into a readable string much like hexadecimal notation for numbers. You can encode anything including a jpg (which is basically a sequence of bytes including possible null bytes). You can encode it when you store a value eg in a database to prevent null bytes messing things up and when you ...


8

I'd prefer Option #4: Avoid relying on inheritance. Just make UrlBuilder an interface, and give people some way to inject their own implementation to the process, overriding the default you provided. interface UrlBuilder { public function url($config); } class DefaultUrlBuilder implements UrlBuilder{ public function url($config) { $config = ...


1

I have answered this question on StackOverflow as well - I place my answer here for easy reference... The PRG pattern alone will not prevent this, as the P action in it takes time (which is usually the case) and the user can submit the form again (via click or browser refresh), which will cause the PRG pattern to "fail". Note that malicious users can also ...



Top 50 recent answers are included