Codesleeve\Stapler\Factories\File::create PHP Method

create() public static method

Build a Codesleeve\Stapler\UploadedFile object using various file input types.
public static create ( mixed $file, boolean $testing = false ) : Codesleeve\Stapler\File\UploadedFile
$file mixed
$testing boolean
return Codesleeve\Stapler\File\UploadedFile
    public static function create($file, $testing = false)
    {
        if ($file instanceof SymfonyUploadedFile) {
            return static::createFromObject($file);
        }
        if (is_array($file)) {
            return static::createFromArray($file, $testing);
        }
        if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') {
            return static::createFromUrl($file);
        }
        if (preg_match('#^data:[-\\w]+/[-\\w\\+\\.]+;base64#', $file)) {
            return static::createFromDataURI($file);
        }
        return static::createFromString($file);
    }

Usage Example

Example #1
0
 /**
  * Test that the file factory can create a Codesleeve\Stapler\UploadedFile
  * object from a string filepath.
  *
  * @test
  * @return void
  */
 public function it_should_be_able_to_build_a_stapler_uploaded_file_object_from_a_string_file_path()
 {
     $uploadedFile = File::create(__DIR__ . '/../Fixtures/empty.gif');
     $this->assertInstanceOf('Codesleeve\\Stapler\\File\\FileInterface', $uploadedFile);
 }
All Usage Examples Of Codesleeve\Stapler\Factories\File::create