Overview

Namespaces

  • Scene7
    • Commands
      • Layer
    • Definitions
    • Helpers
      • Html
        • Attributes
    • Requests

Classes

  • Factory

Interfaces

  • RenderInterface
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 
<?php

namespace Scene7;

use Scene7\Commands\Layer;
use Scene7\Requests\AbstractRequest;

class Factory
{
    /** @var string */
    protected $baseUrl;
    /** @var callable */
    protected $defaultsCallback;
    /** @var callable */
    protected $layerDefaultsCallback;

    /**
     * @param string $baseUrl the base url
     * @param callable|null $defaultsCallback has one parameter, $request that is the request object
     */
    public function __construct($baseUrl, callable $defaultsCallback = null)
    {
        $this->setBaseUrl($baseUrl);

        if (is_callable($defaultsCallback)) {
            $this->setDefaultsCallback($defaultsCallback);
        }
    }

    /**
     * @param string $file
     * @return Requests\Image
     */
    public function newImage($file)
    {
        $image = new Requests\Image($this->baseUrl, $file);
        $image->setFactory($this);
        $this->_setNewRequestDefaults($image);

        return $image;
    }

    /**
     * @param int|string $id
     * @param string|null $name
     * @return Layer
     */
    public function newLayer($id, $name = null)
    {
        $layer = new Layer($id, $name);
        $this->_setNewLayerDefaults($layer);
        return $layer;
    }

    /**
     * @param string $baseUrl
     * @return $this
     */
    public function setBaseUrl($baseUrl)
    {
        if ($baseUrl[strlen($baseUrl)-1] !== '/') {
            $baseUrl .= '/';
        }

        $this->baseUrl = $baseUrl;
        return $this;
    }

    /**
     * @param string $protocol
     * @return $this
     */
    public function setProtocol($protocol)
    {
        $this->protocol = $protocol;
        return $this;
    }

    public function setDefaultsCallback(callable $callback)
    {
        $this->defaultsCallback = $callback;
        return $this;
    }

    protected function _setNewRequestDefaults(AbstractRequest $request)
    {
        if (is_callable($this->defaultsCallback)) {
            $callback = $this->defaultsCallback;
            $callback($request);
        }

        return $this;
    }

    protected function _setNewLayerDefaults(Layer $layer)
    {
        if (is_callable($this->layerDefaultsCallback)) {
            $callback = $this->defaultsCallback;
            $callback($layer);
        }

        return $this;
    }
}
API documentation generated by ApiGen