Jump to content


  • Content count

  • Joined

  • Last visited

Community Reputation

3 Neutral

About Drongo_III

  • Rank
    Prolific Member

Profile Information

  • Gender
  1. Drongo_III

    Docker Basic Question

    Hi Gizmola Thank you for your detailed response. I really appreciate the help as wrapping my head around this is taking precious time. I'm still a little confused on the 'single responsibility' approach to creating services. For instance, looking on Dockerhub there are images for Centos, httpd, PHP. And presumably it's preferable to use the official Dockerhub images than spinning up centos and installing apache/php myself? Assuming using the Dockerhub images is the correct method then should I have three dockerfiles as follows? one dockerfile with: FROM centos:7 one dockerfile with: FROM httpd:latest one dockerfile with: FROM PHP:7 Then I just network these (guessing bridge network) and the services automatically know how to talk to each other? Sorry if I'm labouring this one, just want to get the concepts right before diving in. Thanks, Drongo
  2. Hi Guys I have a basic question around Docker, which I'm right at the start of learning. I'm building a basic LAMP environment and I've come across a few pointers in the docks which seem to indicate (though don't explicitly state) that you should create containers so they run a single service per container. What this appears to mean is that for a LAMP environment I should have Apache+PHP on one container and MySQL on another container. So my questions... 1) Is this in fact the best practice way of building containers and environments? If yes, 2) How do they work together and talk to each other to form an environment? 3) Should you have multiple dockerfiles for each container housing a service (e.g. apche+php) 4) Should your application code go on the apache+php container? Or should that be a container in itself? Sorry if these are really noob questions but I'm more used to paradigm of VMs so docker is a bit confusing. Thanks, Drongo
  3. Drongo_III

    RESTful APIs

    Hi Guys I'm about to start a project building a lot of APIs. I've built basic REST APIs in the past but I mostly made up the standards for the API. I want to do this project properly from the start but I don't know whether there is an official 'standard' you should follow when creating a REST APIs? Like JavaScript has ECMA but I can't seem to find an api governing body as such and to be honest I've never known of one even after many years being a dev. Alternatively if that doesn't exist can anyone recommend good websites which highlight best practice? Thanks, Drongo
  4. Drongo_III

    Bash and heredoc

    Hello I'm really green when it comes to bash... Trying to create a script which will SSH into multiple servers and report back a list showing the status of a deployment on each. The intention is for the script to run from my local machine. I read using heredoc is the way to go but I don't think its possible to store variables which are accessible outside of the sub-session - i.e. you can't store variables inside heredoc and have them accessible outside So my question is does anyone know a good way to get the variables from heredoc into the 'higher level' bash script so I can aggregate the results from each server? Pseudo code to illustrate what I'm aiming for: ssh me@ << EOF # Get server Status to variable EOF ssh me@ << EOF # Get Server Status to variable EOF echo $SOME_VARIABLE_OF_STATUS_FROM_EACH_SERVER
  5. Drongo_III

    Deploying with Git

    Hello I want to deploy an application hosted on Git Hub. It's my first time doing it this way. () I've cloned the application on my web server and everything works great. I've done some additional changes locally and pushed them up to Git Hub along with a tag (called testTag). I understand tags are common practice to mark a release point. The bit I'm confused by is how I deploy that specific tag to my server? I want to be able to checkout the tag to my server's master branch but when I checkout the tag (code below), it kicks me off the branch. Not what I was hoping for. git fetch --all --tags --prune git checkout testTag Any advice appreciated! And I know this isn't strictly PHP but I couldn't see a forum relevant to this. If it's any consolation it is a PHP application I'm trying to deploy Drongo
  6. Drongo_III

    Negative Lookbehind

    Thanks for the reply Jacques. I'll certainly give your advice some consideration. Out of interest though, and in an effort to understand lookbehinds more, can u answer me: 1) is it possible to follow a lookbehind with a character class? Or is this not permitted? 2) what do you mean when you say the regex I've used will always be true. Doesn't that regex mean 'match a slash, then match anything that is not precedes by admin'? Therefore /admin/somepage shouldn't match. I say this because I thought lookbehinds acted at the point where they are defined so in my example why does the opening slash have any impact on the lookbehind and the expression that follows it? Thanks, Drongo
  7. Drongo_III

    Negative Lookbehind

    Hi Guys Stuck on what is probably a very easy thing. I'm adding wildcard route to an application and I'm using regex to match anything UNLESS it's preceded by /admin/ in which case I don't want the match to succeed. I want to match: /foo/bar/ I don't want to match: /admin/foo/bar I figured this was a job for Negative Lookbehind but it doesn't work when I follow the lookbehind with a character class like so: ^\/(?<!admin)[a-z0-9\-\/]* This doesn't work as /admin/test/ still matches the full string - even though I would expect anything following the word 'admin' to fail. So either you cannot use a character class after a lookbehind, or I'm doing it wrong. Any advice would be most welcome! Drongo
  8. Drongo_III

    Mapping data to Models

    Thanks Requinix That makes a lot of sense. Appreciate the advice. Drongo
  9. Drongo_III

    Mapping data to Models

    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?
  10. Drongo_III

    Mapping data to Models

    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( 'name'=>array( 'modelSetter'=>'setName', 'modelGetter'=>'getName' ), 'email'=>array( 'modelSetter'=>'setEmail', 'modelGetter'=>'getEmail' ), /* 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] ); } } } //NOTE THIS IS JUST TYPED IN AND NOT TESTED CODE
  11. I recently went through this. In respect of speeding up load time you may wish to consider some of these too: Place your scripts at the bottom of your html above the closing body tag Consider using the 'async' attribute on scripts which aren't essential Consider aggregating your scripts into a single file for production (something like gulp could be automated to do this). This means fewer server calls. Create image sprites where appropriate and aggregate SVGs into an icon font (sites like icomoon are handy here). Again, fewer server calls. 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 Run all images assets through something like https://tinypng.com/ (equivalents for jpeg etc) as this can strip huge amounts from image file sizes. 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. Drongo
  12. Drongo_III

    Best practice for passing data to db class

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

    Best practice for passing data to db class

    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?
  14. 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? <?php 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; } }
  15. Drongo_III

    OOP/OOD advice

    Thanks for all your help Requinix!

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.