Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p>The factory should <em>only</em> care about creating entities. I personally preferr to put validation both in my views and in the model layer. I'd use some library like jQuery's validation plugin to make some <strong>essential</strong> validation on the client side (like checking if required fields have data). And then do the "hardcore" validation on the model. I do this is by using a simple BaseEntity abstract class which all entities extend, and since you asked for an example, here it is: </p> <pre><code>abstract class BaseEntity { public function isValid(); } class MyEntity extends BaseEntity { public function isValid() { //actual validation goes here } } </code></pre> <p>You could also make use of a static helper class with some basic validation methods:</p> <pre><code>class ValidationHelper { public static function isValidPhonenumber($value) { //check valid phonenumber, using a regex maybe } public static function isAlphanumeric($value) { //check for letters and numbers only } } </code></pre> <p>Many argue against static methods because they can break unit tests, but in this case they are pretty basic and they don't have external dependencies, thus making them "safer".</p></li> <li><p>When it comes to checking for already existing entities you can do this by querying your DB to see if the entity is already there before adding/updating, or (this is how I like to do it) you could add a <code>unique</code> index to those columns that can't be repeated in the DB, and then wrap the create or update queries in a try-catch block (the query will throw a unique constraint violation, if two users have same e-mail for example) and then show the proper error message</p></li> <li><p>On your last question it comes down to a matter of preference. If your DB will get a million hits in 1 minute, then it's probably better to use lazy loading to avoid fetching unnecesary data until it's needed. But if your database is relatively small you could perfectly use eager loading without sacrificing too much performance. Again, this is a matter of personal preference.</p></li> </ul> <p>hope some of this rambling makes sense, cheers!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload