2017 © Pedro Peláez
 

standard scene7

Adobe Scene7 PHP SDK

image

joshuaadickerson/scene7

Adobe Scene7 PHP SDK

  • Friday, July 14, 2017
  • by joshuaadickerson
  • Repository
  • 3 Watchers
  • 3 Stars
  • 862 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Adobe Scene7 HTTP Protocol API

A library to create request strings for the Adobe Scene7 HTTP Protocol., (*1)

Installation

The easiest way to install this library is with Composer composer require joshuaadickerson/scene7, (*2)

There is no version yet since I'm not ready to call it stable., (*3)

The minimum PHP version is 5.6., (*4)

Build Status Documentation Status, (*5)

Factory

The factory should be used to create a new request and layers., (*6)

// See "Factory Defaults Callback"
$factory = new Scene7\Factory('https://www.example.com', $callback);
$image = $factory->newImage('myProductImage');
echo $image->render();

// Output:
// https://www.example.com/myProductImage?defaultImage=MyDefaultImage&id=42

All requests and helpers also implement __toString() so you don't have to call render() directly., (*7)

Factory Defaults Callback

I decided that instead of trying to implement a defaults setter using an array or an object or something else, I would use a callback. This allows you to do a lot more than with another method., (*8)

$callback = function (AbstractRequest $request) {
    // Apply defaults based on the request type
    switch ($request->getRequestType()) {
        case 'img':
            $request
                ->setDefaultImage('MyDefaultImage')
                ->setId(rand(0, 100));
            break;
    }
}

You can set the layer defaults the same as well. They will only be applied when you add a new layer., (*9)

Helpers

Picture

You can quickly create a picture tag with nested <source> and <img> tags., (*10)

The easiest way to create a picture tag is using Picture::addSourceListFromImage()., (*11)

Example

$picture = new Scene7\Helpers\Html\Picture;
$image = new Scene7\Requests\Image('https://example.com/', 'myProduct');
$queries = [
    // The key is the media query
    // The value is an array of k/v pairs where the key is the HTML attribute you want to set
    '(min-width: 1000px)' => [
        // Width and height get multiplied based on $multipliers (see below)
        'width' => 500,
        'height' => 500,
    ],
    '(min-width: 500px)' => [
        'width' => 250,
        'height' => 250,
    ],
];
$picture->addSourceListFromImage($queries, $image, [2, 1])->setImage($image);

echo $picture->render();

// Output:
// <picture><source media="(min-width: 1000px)" srcset="https://example.com/myProduct?wid=1000&hei=1000 2x,https://example.com/myProduct?wid=500&hei=500 1x,"><source media="(min-width: 500px)" srcset="https://example.com/myProduct?wid=500&hei=500 2x,https://example.com/myProduct?wid=250&hei=250 1x,"><img src="https://example.com/myProduct?" alt=""></picture>

Contributing

This is maintained. I don't want to give the impression that it's not. I plan on doing some things with this and I use it at work. One of the big reasons for open sourcing it though, is so I don't have to do all of the work., (*12)

Feel free to submit pull requests. Please add tests with your PR so I can merge it faster., (*13)

If you have a feature request or issue, I consider that a contribution and welcome them., (*14)

TODO

  • implement all of the request types
  • test everything
  • figure out the "src" command documentation
  • implement mask
  • more helpers like audio and video
  • documentation
  • examples
  • fix obscured queries
  • add Travis CI config
  • add some cool things to this readme to show if it's successfully building and the test coverage

License

This work is licensed under the BSD-3 clause license, (*15)

Association with Adobe

Adobe and Scene7 are trademarks of Adobe Systems Incorporated. This package has no association with them. I would love if Adobe stepped up and took over maintenance of this and distrubted it as official, but that is not the case as of now. This is not an official package., (*16)

The Versions

14/07 2017

dev-master

9999999-dev

Adobe Scene7 PHP SDK

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6

 

The Development Requires

by Joshua Dickerson