     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

    <?php

    namespace Catapult;
    /**
     * Generate a resource location
     * for Catapult. Either initialize
     * as object or accessible by one time
     * command: Make/2
     */

    class URIResource extends BaseResource {
        /**
         * Object form of URIResource
         * should allow to
         * same functionality
         * as Make/2 when casted to
         * string
         * @param $path -> partial path
         * @param $extras -> extra endpoints
         */
        public function __construct($path, $extras=array())
        {
            $this->path = $path;
            $this->extras = $extras;
        }

        /**
         * Straight forward
         * making of string
         * seperator can
         * be changed for queriying
         * @param $path -> partial path
         * @param $extras -> extra endpoints
         */
        public static function Make($path, $extras=array(), $sep="/")
        {
            $ext = "";

            if (sizeof($extras) > 0)
                foreach ($extras as $e)
                    $ext .= (string) $e . $sep;

            /* dont seperate if no extras were provided */

            if ($ext != "")
                return $path . $sep . $ext;

            return $path;
        }

        /**
         * Look in make for more
         * URIResource should
         * only allow its contents to be fetched
         * through this
         */
        public function __toString()
        {
            return (string) self::Make($this->path, $this->extras);
        }
    }

    /**
     * Represent object in string
     * form. Where form must be compilant
     * of:
     * (CLASS)(op1,op2..op)
     */
    class StringifyResource extends BaseResource {
        public function __construct($class, $options)
        {
            $this->class = $class;
            $this->options = $options;
        }

        /**
         * Make the string
         * directly
         * @param $class -> __class__
         * @param $extras -> list of parameters to encode
         */
        public function Make($class, $extras)
        {
            return "";
        }

        public function __toString()
        {
            return self::Make($this->class, $this->options);
        }
    }