Monday, June 24, 2019

Keeping 2+ Versions of Code

Creating a custom framework using Slim as the bases, I had to create a small modal that could be used in general. After finalizing the code the modal was pushed into a project that was deployed into production. However, having to use the same modal for another project I realized I had to make some adjustments. This made me want to see how to work with version and if my own custom code could be versioned. I could have made the change and tested the project on production, however I felt I had an opportunity to test out versioning. Production custom Code: composer labeled this code as version ^1.0 Development custom Code: composer labels dev code as dev-master Composer will retrieve the most resent commit of the master if the label is dev-master. As soon as there is a number convention, composer will retrieve that particular commit that was the latest at that time and retrieve on that. Versioning has become that simple, you do not have to create multiple 'jar' files anymore of your code. Test this by making a small change to your code. My example is retrieving content using WordPress API.

public function getPage($id) {  
   try{    
    $uri = $this->wp_api . '/pages/' . $id;
    $response = $this->httpClient->request("GET", $uri, []);
    return  $this->getContent($response);  
   }  
   catch (\Exception $e){    
     $this->logger->error('getPage Err',[$e->getMessage()]);    
     throw new \Exception($e->getMessage(),$e->getCode());  
   }
}

To

public function getPage($id) {  
 try{    
   $uri = $this->wp_api . '/pages/' . $id .'?_embed';    
    $response = $this->httpClient->request("GET", $uri, []);
    return  $this->getContent($response);  
 }  
 catch (\Exception $e){    
   $this->logger->error('getPage Err',[$e->getMessage()]);    
   throw new \Exception($e->getMessage(),$e->getCode());  }
 }

Composer file looks like the following:

"require": {     
    ...
    "lit-framework/mod_wp_content": "^1.0"},

"require": {     
    ...
    "lit-framework/mod_wp_content": "dev-master"},

Run composer update command on both projects and see the outcome. 
First one, the code remains as
$uri = $this->wp_api . '/pages/' . $id; and second project the same dependency 
now as new code of 
$uri = $this->wp_api . '/pages/' . $id .'?_embed';