andriinavrotskii / hexatest2016
图片加载器
Requires
- php: >=7
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-23 13:57:38 UTC
README
测试任务 | 中级开发者
编写一个Composer包,用于从远程主机加载图片并将其保存到文件系统。包应执行所有可能的检查,并在出现异常情况时抛出异常。支持的图片格式为jpg、png、gif。代码应添加注释,遵循psr-2风格。自动加载器遵循psr-4规范。注释采用phpdoc格式(可选)。单元测试使用phpunit(可选)。将代码上传到Github。执行测试的时间标准为3小时。
composer.json
{ "require": { "andriinavrotskii/hexatest2016": "dev-master" } }
简单用法
$url = 'http://some_valid_url/image.jpg'; $imageLoader = new ImageLoader(); $result = $imageLoader->load($url);
如果一切正常,图片将被保存到php的临时目录。
$result: Array ( [path] => /tmp/ [name] => 269497fd3602fb3a1c7c936c5493a7b2.jpeg [file] => /tmp/269497fd3602fb3a1c7c936c5493a7b2.jpeg )
高级用法
$path = DIR . 'some/path'; $mime = ['image/jpeg', 'image/png', 'image/gif'];
$imageLoader = new ImageLoader($path); $imageLoader->setAllowMimeTypes($mime); $imageLoader->setAllowRewriteFile(false);
$url = 'http://some_valid_url/image.gif'; $name = 'my_image'; $result = $imageLoader->load($url, $name);
$result: Array ( [path] => DIR . '/some/path/' [name] => 'my_image.gif' [file] => DIR . '/some/path/my_image.gif' )
$url = 'http://some_valid_url/image.jpg'; $result = $imageLoader->load($url);
$result: Array ( [path] => DIR . '/some/path/' [name] => 597457a73957b1c4513ce0c2b1374cf1.jpeg [file] => DIR . '/some/path/597457a73957b1c4513ce0c2b1374cf1.jpeg' )