chain static method with non static methods in trait

722 Views Asked by At

i have trait like this

namespace Files;

trait Upload {

   //  name of input form
   public $inputName;
   // directory that you chose to upload file
   public $directory;
   //uploaded file name
   public $filneName;
   public $fullUploadedAdress;
   //uploaded file extention
   public $ext;
   //uploaded file size
   public $fileSize;
   // errors
   public $error;

   public  function Input ( $inputName )
   {
          //RETURN NAME OF UPLOAD FORM INPUT
          $this->inputName = $inputName;
          return $this;
   }
}

and another class like this

namespace RequestResponse;

class SetAndGetMethod
{
   use \Files\Upload;

   static protected $uploadInputName;
   protected static $onlyInstance;

   function __construct () { }

   public static function __callStatic ( $methodName, $args )
   {
          if ( preg_match ( '~^(post|get|request|file)([a-z|A-Z])(.*)$~', $methodName, $matches ) ) {
                 $property = strtolower ( $matches[ 1 ] );
                 $inputName = $matches[ 2 ] . $matches[ 3 ];
                 if ( !method_exists ( __CLASS__, $property ) ) {
                        throw new \Exception( 'Property ' . $property . ' not exists' );
                 }
                 switch ( $matches[ 1 ] ) {
                        case 'post':
                               return self::post ( $inputName );
                        case 'get':
                               return self::get ( $inputName );
                        case 'request':
                               return self::request ( $inputName );
                        case 'file':
                               return self::request ( $inputName );
                        case 'default':
                               throw new \eimaException ( 'Method ' . $methodName . ' not exists' );
                 }
          }
   }


   protected static function getself ()
   {
          if ( static::$onlyInstance === null ) {
                 static::$onlyInstance = new self;
          }
          return static::$onlyInstance;
   }


   public static function file ( $property )
   {
           self::$uploadInputName = $property;
          new self;
   }

}

when i call my fileUpload method with setters and chain this method to my trit i get this error

Input::fileUpload()->Input('Upload');

Fatal error: Call to a member function Input() on a non-object in C:\wamp\www\Framework\protected\controller\Home_Controller.php on line 27

0

There are 0 best solutions below