2017 © Pedro Peláez
 

library dario

SimpleXML a given XML file. Extract data and store

image

webnanogy/dario

SimpleXML a given XML file. Extract data and store

  • Tuesday, July 18, 2017
  • by darusca
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 4 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

1. Project Details

1.1 Design Patterns:

MVC, Repository, (*1)

  • It is designed with the Repository Pattern, which allows a Controller to pass data to the Repository which in turn interfaces with the Model., (*2)

  • This is achieved by injecting a repository Dependency in the Controller, so that the repository implements its interface with the model, starting in the Controller., (*3)

  • OOP (Interfaces, Namespaces, Encapsulation, Information Hiding, properties and methods Accessibility, Static, Dynamic, etc.)., (*4)

All this ensures the code is: - Testable (injection are mocked) - Maintainable (OOP not procedural) - Reduced code (reusable), and - Less bugs (info hiding, accessibility, encapsulation, etc), (*5)

Note: The specifics for this Development Environment follows:, (*6)

Virtual Box, Vagrant, Centos 7, PHP 5.6, MySQL 14.14, PHPMyAdmin, git, composer, artisan, pear, PHPStorm 2017 with XDebug, Code Sniffer (phpcs), GitHub);, (*7)

1.2 Web Server requirements:

  • PHP >= 5.6.4
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

2. Front-End Technical Details

Input: the config.XML

The blade template receives the the associative array() containing the config.XML data, (*8)

Process:

  • The Blade engine iterates, displays and attributes (custom 'data-' attributes)* this associative array data.
  • JQuery stores these 'data-'* into variables.
  • A JavaScript Object (class) initializes JQuery, binds/fires the button click event, and processes server response.
  • JQuery asynchronously posts the data to '/create' route

Output:

  • Client is notified when sending/saving ('button is disabled'), and on saved ('on success button is enabled').
  • Display server response.

3. Back-End Technical Details

Input:

  • The server accepts two (get/post) requests in the routes, namely 'receive' and 'create'
  • Request handling logic are mapped to 2 Controller class methods respectively

Process:

  • An Utility class parses the config.XML file, using the native 'simplexml_load_file()' PHP function
  • 'simplexml_load_file(config.XML)' returns an associative array() containing the config.XML data (ex: 'title', 'description' ...)
  • These data is persisted in the database during the click event process from the front-end

Note: This project uses the SimpleXML - PHP5’s new API for accessing the contents of XML documents., (*9)

Output:

  • The Controller returns the package view with this associative array()
  • When the data is to be persisted to the db, the Controller responds to the asynchronous call appropriately

4. Framework

Laravel 5.4 (PHP v5.6)

Q: Why Laravel?, (*10)

A: Choices! Everybody is using it and it works well. I just like the brand, though some online resources ought to be free, as is most community support, (*11)

5. Usage

5.1 Installation:

  1. Install Laravel 5.4
  2. Install this package, (*12)

    composer require webnanogy/dario
  3. Run the following command inside this app's root directory, (*13)

    composer install
  4. Modify .env DB, (*14)

    Ex: DB_CONNECTION='target DBMS'
    DB_HOST='target IP address'
    DB_PORT='target DBMS connection port'
    DB_DATABASE='target DBMS db name'
    DB_USERNAME='target DBMS user name'
    DB_PASSWORD='target DBMS user password', (*15)

  5. Change the .env file 'APP_URL' for the target server EX: APP_URL='target server app url', (*16)

  6. Migrate the package/laravel tables by running:, (*17)

    php artisan migrate, (*18)

  7. Publish the config.XML and assets, (*19)

    php artisan vendor:publish, (*20)

5.2 Setup Routes

Copy the following to the apps 'routes/web.php', (*21)

5.3 Run Laravel

Run Laravel home page and append receive EX: http.../localhost/laravel/output/public/receive, (*22)

6. Assumptions

Given the spec, the assumptions follow:, (*23)

Routes:

'receive' and 'create', (*24)

The config.XML File:

The config.XML path will be defined in the .env file., (*25)

Because it is a configuration file, I assumed that the structure will not change often ('from time to time'). So the code is strongly coupled around the given config file, and will choke with a different XML file structure., (*26)

7. Plugins and 3rd Party Libraries:

All functionality required to fulfill most of this project's requirements was implemented with the Laravel ecosystem and PHP native functions., (*27)

8. Coding Standards:

PSR-1/2/3/4, (*28)

9. Scaling Considerations

  • This app design is Decoupled with separate concerns for Presentation and Business logic, allowing for scalability of this package
  • Decoupling also increases the lifetime since it is not tied to any technology or concrete implementations
  • Packages folder structure enables future growth, such as Models, Assets and other sub-folder structures

10. Performance Considerations

  • Data is posted asynchronously so the UI (User Interface) is not blocked or stalled, improving performance
  • Laravel's cache design is optimal as well as the management of pool resources such as database connections and termination
  • No Form here means no need to store flashed old input Session Data in the event of errors
  • For PHPUnit testing performance this app does not access the model directly. So it is possible to bypass database, otherwise, would be expensive to make database calls

Credits

Dario Alfredo, (*29)

The Versions

18/07 2017

dev-master

9999999-dev

SimpleXML a given XML file. Extract data and store

  Sources   Download

by Dario Alfredo

17/07 2017

dev-add-license-1

dev-add-license-1

SimpleXML a given XML file. Extract data and store

  Sources   Download

by Dario Alfredo

15/07 2017

1.0.0

1.0.0.0

This package creates entries to the Database using Attributes or Elements from the provided XML File.

  Sources   Download

by Dario Alfredo