Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by Drongo_III

  1. 13 hours ago, requinix said:

    Need more details.

    Or try from another angle. What kind of code do you want to write in order to get the data you need?

    I actually dusted off my copy of Patterns of Enterprise Application Architecture and there was a chapter on DTOs.  In that chapter it  recommends using a 'DTO Assembler' which is an type of Mapper - i.e. an intermediary to keep the DTO ignorant of the Models that supply it's data.  And this seems to solve the very problem I'm trying to solve, I just didn't have a name for it and incorrectly thought 'factory must be what i need'.

  2. I'm working on a new project and need to create DTOs for use in views (this is a Laravel project so MVC). The DTO will get created from subsets of values from 2 other models (Price, Quote). Obviously, it wouldn't be ideal to build the DTO from those models in multiple places so I want to seat that logic in a specific class.  I figure an approach is to use a factory - i.e. as a place to capture the creation of the DTO. But when I read into Factory Method and Abstract Factory  and Simple Factory this use case doesn't sound like it fits.

    So my questions are:

    1. Is a factory the right pattern?
    2. If so, which flavour of factory would you suggest?
    3. Is this the way you would approach it?  I appeal to the more experienced minds here for some insight. I work alone so it's hard sometimes to figure out the right approach.




    • Like 1
  3. Hello

    Trying to find MaxRequestWorkers apache setting but cannot locate it anywhere. I have tried grepping the entire httpd directory but there is no mention of it. 

    Running Apache/2.4.48 mpm-prefork-module.  

    So two questions:

    1. Can apache configuration values NOT be explicitly set?
    2. In the event that it's not explicitly set does Apache fallback to an 'invisible' default?
    3. Is there a way to list specific apache config settings from the command line?

    Pulling my hair out so any help is greatly received.



  4. Not sure if this the place to ask or not. Hoping someone can give me a steer.

    I'm implementing agile scrum for the first time at my organisation. I'm trying to understand story point estimation but it's a little confusing.

    I've read many articles stating that you take a reference story (one for which project participants can easily reason about to estimate it accurately) and place points on that reference story using it as a yard stick for the estimation of further tickets. And the points are usually selected from a number in the Fibonacci sequence.

    The bit I don't understand is that many guides suggest the teams all put in their estimates. Dev may say a story is 8 points, QA may say the same story is 3 points, System Architects may say it's 8 points.

    What do you place on the final story? Is it 8 points because that's the highest estimate? Or do you sum all the points (in this case 19 points) so the story is representative of the collective effort?

  5. Thanks guys - it helps to get another perspective.  I quite like the idea of view-models/business-models/DTOs whatever you want to call them as I too subscribe to the idea that views should do as little thinking as possible - especially when the view is comprised of multiple components from different database models.  But I take your points that coupling has to happen somewhere and database change is likely to be infrequent.  I suppose it's a matter of consistency on the project too so for this project I'll stick to the current method.

  6. Hi there

    I've recently been working on a Laravel project.  It's a project I've been drafted in to work on and I've not used Laravel before.

    My question is one of what is considered good practice.  In this project the controllers pass whole models back to the view.  For instance, its the norm on the project to pass back a whole booking model just to get at a couple of attributes like booking->id and booking->name.  As these attributes represent database columns it feels a bit wrong to pass these around because you're effectively coupling the view to the structure of the database. I know behind the scenes Laravel is using a magic method to access the properties so you could argue they are wrapped in a method and therefore don't expose the direct database structure to views. 

    So the question is, would you pass database models directly to views in this way? Or is it 'better' to map those models to an intermediary model that is dedicated to the view (a sort of dto)?




  7. 3 hours ago, requinix said:

    Well there ya go. The system temp directory should be writable by virtually everyone - it's the temp directory, it's supposed to be usable for creating temporary files.

    That's great. But I was hoping to gain some insight into what drives that buffering behaviour. Does it just kick in after post size is over a certain amount? I can't seem to find any settings that state they make post data buffer.

  8. Hi Requinix

    Thanks for the fast response.

    I'm not too worried about the error as it sounds self explanatory to fix. The full error was:

    PHP Warning: Unable to creeate temporary file, Check permissions in temporary files directory. in unknown
    PHP Warning: unknown: Post data can't be buffered; all data discarded in unknown

    There's no temp directory in php.ini so it seems to be falling back to the system temp directory for which apache doesn't have permissions.  

    But the essence of what I'm trying to figure out is what may influence it buffering post data to a temp directory. As this may in turn let me figure out the best course of action for fixing the issue.

    Also, I'm using mod_php.


  9. Hi Guys


    I'm getting the following error when sending large post data to a PHP 7 application:

    PHP Warning: Unknown: POST data can’t be buffered; all data discarded in Unknown on line 0


    I think I have a fix for this now, so the error isn't the source of my question. It just got me wondering two things:

    1. Does PHP always buffer data to a temporary file? Or is it only when post data is of a certain size?
    2.  Are there any php.ini settings that directly influence this behaviour?  I have trawled through the common ini settings but nothing (that i can find) mentions buffering.




  10. Sorry if this post doesn't belong here or anywhere else on this site.

    I'm trying to build a Jenkins pipeline using the declarative Jenkinsfile.  I've used the Git SCM plugin to pull down the main GitHub repo for the build. It gets triggered off a GitHub Webhook.  This works great.  The next thing I want to do is pull in another repository for the same build step that contains the build code (i.e. the steps for building the application that came down with the original Git SCM trigger). I want to separate it because the build code is common to a number of applications i'll be building so makes no sense to store it with each application.

    The problem comes when I try to checkout another repo in my build step. It effectively wipes out the repository files from the original SCM checkout that happened when it was triggered.  What i was expecting to happen is to be able to checkout the additional build repository files to a sub-directory leaving the original files in tact. But that doesn't happen.  Am I using this incorrectly? Or is it just how the plugin works that you're only allowed to checkout one repo at a time?


    I've added an excerpt from my Jenkinsfile below. It's the checkout step below that seems to wipe out the repo that was pulled down when the build was triggered.


    stages {
        stage('Building') {
            steps {
                sh "mkdir test && cd test"
                //use this to checkout the repo for build script
                checkout([$class: 'GitSCM',
                   branches: [[name: '*/master' ]],
                   extensions: scm.extensions,
                   userRemoteConfigs: [[
                       url: 'git@github.com:XXX/build-code.git',
                       credentialsId: 'XXX-XXX-XXX-XXX-XXX'


  11. Having to maintain a mapping is cumbersome. Do you have any attachment to being able to separate the model from the form? Would it be so bad to consider the model (this model) as a "form model" and have form fields map directly to object properties?


    Thanks for picking this up Requinix


    Well the thinking was I could use mapping classes to:


    1) Shuttle data from forms to the model (and model to forms)

    2) Shuttle DB model data to an instance of a model


    And thereby have it all sort of neatly managed in one spot.


    I guess the thing that drove me towards considering a dedicated mapper class is that the model would need to retain references to form field names which won't always have a 1:1 relationship with model property names. And the question in my mind was 'should the model need to know anything about the form?' because there will be a few properties on the model which don't all come from the form.  This sort of left the model feeling like a mixed bag.


     Is it not considered good practice to utilise mapping classes? And if you do use a mapping class is it ok to list out the getters and setters as I have done?

  12. Hello...(again)


    I'm hoping for some advice from the good folks here.  Sorry I keep asking questions but I work alone so it's kind of hard to code review your own ideas...


    Anyway I have a User Model and I want to be able to pass data submitted via $_POST ( which has been validated) to the model and map each piece of form data to its intended property.


    I was thinking of creating a mapping class (basic outline below).  Essentially I'd have an array with form field names as a key and then a sub array mapping to the name of it's counterpart  setter/getter method on the user model.  


    In one respect I think this is good in that the model remains ignorant of the form.  On the other hand the array could become quite cumbersome for forms with lots of questions.  


    Does anyone have a view on whether this is a good/bad approach? And whether there's actually a better way to shuttle $_POST data to a model and getting form data back from a model?

    * Array which has each form field name as it's primary key that maps to it's 
    * equivalent getter/setter on the desired model
    $formFieldToModelMapping = array(
    		/* Repeated for each form field which has an associated proptery on the user model*/
    * @param $model - some User Model
    * @param $data - array of validated $_POST data e.g. $_POST['name'], $_POST['email']
    public method transferFormDataToModel($data, $model){ // $_POST 
    	foreach($formFieldToModelMapping as $formField=>$accessor){
    		if( isset($data[$formField]) ){
    			$methodName = $formFieldToModelMapping[$formField]['modelSetter'];
                          $model->$methodName( $data[$formField] );
  13. I recently went through this.



    In respect of speeding up load time you may wish to consider some of these too:


    1. Place your scripts at the bottom of your html above the closing body tag
    2. Consider using the 'async' attribute on scripts which aren't essential
    3. Consider aggregating your scripts into a single file for production (something like gulp could be automated to do this). This means fewer server calls.
    4. Create image sprites where appropriate and aggregate SVGs into an icon font (sites like icomoon are handy here). Again, fewer server calls.
    5. Consider loading assets from CDN because some browsers can only maintain a certain number of parallel resource calls against the same domain.  So distributing your resource calls across multiple domains/subdomains can speed up load times
    6. Run all images assets through something like https://tinypng.com/ (equivalents for jpeg etc) as this can strip huge amounts from image file sizes.
    7. Make sure you have the right cache controls as these can have a huge impact.

    I know some of that is off point but might be helpful.



  14. If I were to do as you are trying to do, I would pass the object in rather than have to add another stage of fetching the data from the object to then pass into the table layer.

    One thing which you should certainly change is that you should use bind variables for your PDO statements!  Do not just dump data directly into any SQL statement.


    Thanks Nigel.  The example was simplified but I'd definitely bind the variables.

  15. Well, if you are GETTING then you can just easily SET the data. If you set the data then you can easily save the data.


    Doing it this way

    class userModel{
    	private name;
    	private email;
    	/*lots more properties for user */
    	public function getName(){
    		return $this->name;
    	public function getEmail(){
    		return $this->email;

    would be more secure in my opinion. 


    I might not have been very clear.  I was specifically interested in whether its best to pass the model data as an array to the Table Data Gateway or whether its better to pass the model and user it's getters.  I'm not sure I follow why the setters in the model (which were omitted for brevity) have a bearing on this.  Maybe I'm missing something?

  16. Hello


    I have what might be a really basic question.


    Lets say I have a table data gateway which is dedicated to a 'users' table.


    When it comes to saving a user is it better to pass the User Model to the database layer or collapse the User Model into an associative array and pass that instead?   Code example below (just typed out as an example) - methods Insert and Insert2 demonstrate the two options.


    In one respect I think collapsing the model to an array makes it a little less coupled (which seems like a good thing) but on the other hand passing an associative array still feels somewhat error prone and possibly harder to understand for anyone editing the code in the future.


    So my question is, what would you advise is the best practice in this scenario?

    class userTableGateway
    	* Insert option one : Just pass in array of data
    	public function insert($data){
    		$sql_statement = "INSERT INTO userTable (name, email) VALUES ($data['name'], $data['email'])";
    		/*PDO prepare, execute etc...*/
    	public funciton insert2(userModelInterface $model){
    		$sql_statement = "INSERT INTO userTable (name, email) VALUES ($model->getName(), $model->getEmail() )";
    		/*PDO prepare, execute etc...*/
    	public function update(){ ...}
    	public function delete(){...}
    class userModelInterface {
    	/* some interface for user model */
    class userModel{
    	private name;
    	private email;
    	/*lots more properties for user */
    	public function getName(){
    		return $this->name;
    	public function getEmail(){
    		return $this->email;
  17. Hi Requinix


    I really appreciate your detailed response to this.  It has helped hugely to realise the distinction between a Business Model and a Database model.


    I've had a shot at a reworked example (not tested just typed atm) and I'd welcome your thoughts.  It's pretty much your example but I've removed the auth dependency from the UserModel and changed up the factory a bit.


    There is a table gateway acting as the User Database Model (i.e. just transacting data to and from the database for users) and the User Model now concentrates just on delegating to the table gateway and performing tasks on its own entity.


    I would really welcome your feedback as this is helping me learn...hopefully how to do it the right way.


    Here is the example:

    class UserModel
    private $userTableGateway;
    private $name;
    private $username;
    private $password;
    private $lastLogin;
    public function __construct($userTableGateway){
    * Getters/Setters
    * Everything below probably represents 'actions'
    public function validateLogin($hashedPassword){
    if($hashedPassword == $this->password){
    return true;
    return false;
    * Should these methods be outside the class?
    public function updateUser($data){
    //loop data into current object
    //Delegate to $this->userTableGateway
    public function deleteUser($id){
    //Delegate to $this->userTableGateway
    //return boolean on success/failure
    class UserModelFactory
    public function __construct(){
    * $tableGateway encapsulating all the DB access for user table
    $this->tableGateway = new userTableGateway();
    * Required when you want to find a user and get back a populated UserModel
    public function getUserModelAsDBUser($userName){
    //get data from db
    $dbUserData = $this->tableGateway->getUserData($userName);
    if($dbUserData) {
    //create instance and pass it data
    $userModel = $this->createUserModel($dbUserData);
    return $userModel;
    return null;
    * Required for creating an instance when you want to add a new user
    * and pass optional data to it to be populated into the UserModel
    public function createUserModel(array $data){
    $userModel = new UserModel($this->tableGateway);
    if( !empty($data) ){
    foreach($data as $k=>$v){
    //Call $userModel setters to map raw data to object
    //Could be some sort of mapper class instead of foreach
    return $userModel;
    * Controller Code - i.e. Auth Controller
    $userModelFactory = new UserModelFactory();
    $userModel = $userModelFactory->getUserModelAsDBUser($_POST['username']);
    //some class that runs the same hash algorithm as for stored users
    $hashedUserPassword = new passwordHasher($_POST['password']);
    if($userModel && $userModel->validateLogin($hashedUserPassword) ){
    $userModel->updateUser(); //i.e. refresh the user's db record

    And you said above "Oh, and you may be starting to feel like the way you're doing DI (by passing around the database and encryption stuff) isn't working very well. I would agree with that.".  What would be a better way?  



    Thank Requinix


    That certainly helped to clear up some stuff and its clear I need to go read more about MVC and especially Models.


    I realise your answer was simple and intended to illustrate a point but in general is it ok for models, like a User Model to have mixed responsibilities.  Like is it the responsibility of a user model to provision a login mechanism?  I can see how a user model may be a part of that but it feels like the responsibility of dealing with the process shouldn't belong to a user model.  Or should you have a specific LoginUserModel ?


    Sorry for the extended question i just don't have a real world point of reference for what the model in an application should look like or how much you can put into it.


    If it is considered ok for the user model to be packed with lots of stuff then is this approach correct?

    class UserModel 
    	private $userId;
    	private $userName;
    	private $password;
    	* Some instance of a DB class
    	private $db;
    	* Some encryption class which can generate cipher text
    	private $enc;
    	public function __construct($databaseClass, $encryptionClass){
    		//some database layer like a table gateway
    		$this->db = $databaseClass;
    		//some encryption class which can be used to test a password against a cipher
    		$this->enc = $encryptionClass;
    	public function getFromLogin($username){
    		// 1. Retrieve $_POST[''username], $_POST['Password']
    		// 2. Set values to $this->username, $this->$password
    		// 3. return boolean 
    	public function validateLogin($password){
    		// 1. Turn pasword into cipher text
    		// 2. Match against supplied password
    		// 3. Return boolean
    //Authentication controller - receives request /AuthController/doLogin
    class AuthController
    	public function doLogin(){
    		$db = new $databaseClass(); //e.g. a tablegateway
    		$user = new UserModel($db);
    			$loginSuccess = $user->validateLogin();
    			//do stuff 
  19. Hello


    I'm slowly getting to grips with OOP/OOD  but I would like some advice.


    I try to follow the principles of single responsibility and high cohesion.  I'm struggling a bit to see how these principles work when you try to use composition.


    For instance lets says I have an Authentication class handling login on a website.  On login the Authentication class needs to make a db call to find a given user and test against their stored password.  The user also needs to be stored in session when they successfully login so I also compose Authentication with a Session Manager class.


    The question is am I violating SRP by composing my class with these things? I'm using an MVC so is it better practice to do more in my controller (i.e. run these things as individual actions) rather than composing and encapsulating these things into a single class?


    I find the principles a bit confusing sometimes so a steer in the right direction would be appreciated.



  20. Hello


    I have a really basic regex on a rewrite rule that is causing a 500 error and I cannot see why it would.


    I have a directory called 'help'.  What I want is for anytime someone hits the help directory with a tailing url it will simply get rewritten back to help (there are some ajax generated pages).


    so if someone hits /help/kittens they'll simply get rewritten back to help.


    However, when I try to use the following rewriterule in htaccess it just gives me a 500 error.

    RewriteEngine On
    RewriteRule ^help/([a-z]+) /help [NC,L]

    Any help would be appreciated.





  21. This array feature which you appearently know from PHP is actually very exotic and really only makes sense in the super-sloppy PHP philosophy.


    Technically speaking, you simply cannot apply the index operator to the empty value t['key1']. There's no such thing as null['key2']. If you try this in Ruby, your script will blow up with an error message. The same is true for Python. The only reason why PHP doesn't blow up is because it's specifically designed to accept errors. Instead of telling you to fix your code, it will guess what you mean and create a new subarray for you.


    So this isn't how languages normally works. It's a PHPism.


    Thanks Jacques. You're quite right, I'm a php developer first and didn't realise this was a feature particular to php. Makes much more sense now.



  22. I have a really basic question.


    Why is it you can't create a multidimensional array like this in javascript:

    t['key1']['key2'] = 123;

    I have worked with JS for a long time and I get the proper form is to do something like:

    t['key1'] = {'key2' : 123}

     But I'm just wondering why it's not possible to do the first version?  Is it because JS doesn't know what to cast the 'key2' to?





  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.