Coder Social home page Coder Social logo

eeshim's Introduction

What's an EE Shim?

A shim refers to an abstract chunk of PHP code that performs a single function. They can be invoked in your PHP code or through template tags. To provide a context, it is much like a library class that you'd add to your EE build, but with the following benefits:

  • Encourages Single Responsibility Principle
  • Provides functions to both PHP and template layers
  • Makes code easier to maintain
  • Probably less overhead than an equivalent number of separate Add-Ons (I've not performed proper benchmarks to know this for sure)

Anatomy of a Shim

A shim is just a simple PHP class that extends a parent class. The parent provides some encapsulating code which standardizes how the shim is initialized, executed, and how the results are accessed.

How To Use

Shims can be invoked a few different ways:

Callback Style

ee()->eeshim_model->cropImage(
    array('in' => 'full.jpg', 'out' => 'cropped.jpg', 'scale' => 50),
    function($successData)
    {
        // do something with success
    }, function($errors, $errorData)
    {
        // do something with errors
    }
);

In-Scope
The Callback Style approach loses the scope of the calling code, so in many instances the following approach may be preferred.

$obj = ee()->eeshim_model->cropImage(array(
    'in' => 'full.jpg', 
    'out' => 'cropped.jpg', 
    'scale' => 50
));

$obj->run();

if($obj->hasErrors())
{
    $errors = $obj->getErrors();
    $errorData = $obj->getErrorData();
}
else
{
    $data = $obj->getSuccessData();
}

Template Tags

{exp:eeshim:cropImage in="full.jpg" out="cropped.jpg" scale="50"}

Learn More

The Wiki contains documentation on the available methods.

eeshim's People

Contributors

jonathanwkelly avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.