Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ddrv committed Jul 15, 2020
0 parents commit 838c4a4
Show file tree
Hide file tree
Showing 18 changed files with 1,069 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
12 changes: 12 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Contributing

## Report an issue

Please follow the guidelines below when creating an issue so that your issue can be more promptly resolved:
* Provide information including: the version of PHP and This package, the type of operating system and Web server;
* Provide the complete error call stack if available;
* Describe the steps for reproducing the issue. It would be even better if you could provide code to reproduce the issue;

Do not report an issue if you are asking how to use some feature. You should use the `README.md` file.

Before you report an issue, please search through existing issues to see if your issue is already reported or fixed to make sure you are not reporting a duplicated issue. Also make sure you have the latest version of package and see if the issue still exists.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: "https://www.paypal.me/ddrv"
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Bug report
about: Create a report to help us improve
title: 'Bug'
labels: bug
assignees: ddrv

---

### What steps will reproduce the problem?

### What is the expected result?

### What do you get instead?

### Additional info

| Q | A
| ---------------- | ---
| Library version | 1.?
| PHP version | ?
| Operating system | ?
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ddrv

---
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: feature
assignees: ddrv

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Q | A
| ------------- | ---
| Bug fix? | yes/no
| New feature? | yes/no
| Tickets | Fix #...
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor/
composer.lock
phpcs.xml
phpunit.xml
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020 Ivan Dudarev, https://github.com/ddrv <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[![Latest Stable Version](https://img.shields.io/packagist/v/webclient/helper-form.svg?style=flat-square)](https://packagist.org/packages/webclient/helper-form)
[![Total Downloads](https://img.shields.io/packagist/dt/webclient/helper-form.svg?style=flat-square)](https://packagist.org/packages/webclient/helper-form/stats)
[![License](https://img.shields.io/packagist/l/webclient/helper-form.svg?style=flat-square)](https://github.com/phpwebclient/helper-form/blob/master/LICENSE)
[![PHP](https://img.shields.io/packagist/php-v/webclient/helper-form.svg?style=flat-square)](https://php.net)

# webclient/helper-form

Helper for creating PSR-7 request with files.

# Install

Install this package and your favorite [psr-17 implementation](https://packagist.org/providers/psr/http-factory-implementation).

```bash
composer require webclient/helper-form:^1.0
```

> Now it’s very easy to create file requests for PSR-18 HTTP Clients!
# Using

```php
<?php

use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Webclient\Helper\Form\Wizard;

/**
* @var RequestFactoryInterface $requestFactory
* @var StreamFactoryInterface $streamFactory
*/
$wizard = new Wizard($requestFactory, $streamFactory);

$fh = fopen('/home/user42/.ssh/id_psa.pub', 'r+');

/** @var RequestInterface $request */
$request = $wizard
->createForm('http://localhost:8080/path?query=webclient#fragment', 'POST')
->addField('sign_up[login]', 'user42')
->addField('sign_up[password]', '$ecr3t')
->uploadFromString('about', 'hi!', 'about.txt', 'text/plain; charset=UTF-8')
->uploadFromFile('photo', '/home/user42/images/DCIM_4564.JPEG', 'image/jpeg', 'avatar.jpg')
->uploadFromResource('public_ssh_key', $fh, 'id_sra.pub', 'text/plain')
->createRequest()
;
```
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "webclient/helper-form",
"type": "library",
"description": "Helper for creating PSR-7 request with files",
"keywords": ["http", "client", "psr7", "psr-7", "helper"],
"license": "MIT",
"authors": [
{
"name": "Ivan Dudarev",
"email": "[email protected]",
"homepage": "https://ddrv.ru"
}
],
"require": {
"php": ">=7.0",
"psr/http-message": "^1.0",
"psr/http-factory": "^1.0"
},
"require-dev": {
"nyholm/psr7": "^1.3",
"phpunit/phpunit": "^6.5",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"ext-fileinfo": "Need for defining mime types",
"psr/http-factory-implementation": "Choice your favorite psr-17 implementation"
},
"autoload": {
"psr-4": {
"Webclient\\Helper\\Form\\": "src/"
},
"files": [
"fn.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\Webclient\\Helper\\Form\\": "tests/"
}
}
}
93 changes: 93 additions & 0 deletions fn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

if (!function_exists('mime_content_type')) {
function mime_content_type($filename)
{
if (function_exists('finfo_open')) {
/** @noinspection PhpComposerExtensionStubsInspection */
$info = finfo_open(FILEINFO_MIME);
/** @noinspection PhpComposerExtensionStubsInspection */
$mime = finfo_file($info, $filename);
/** @noinspection PhpComposerExtensionStubsInspection */
finfo_close($info);
return $mime;
}
$types = [
'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',

// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',

// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',

// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',

// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',

// ms office
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',

// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
];
$arr = explode('.', $filename);
$ext = strtolower(array_pop($arr));
if (array_key_exists($ext, $types)) {
return $types[$ext];
}
return 'application/octet-stream';
}
}

function mime(string $file)
{
if (file_exists($file)) {
return mime_content_type($file);
}
if (function_exists('finfo_open')) {
/** @noinspection PhpComposerExtensionStubsInspection */
$info = finfo_open(FILEINFO_MIME);
/** @noinspection PhpComposerExtensionStubsInspection */
$mime = finfo_buffer($info, $file);
/** @noinspection PhpComposerExtensionStubsInspection */
finfo_close($info);
return $mime;
}
return 'application/octet-stream';
}
18 changes: 18 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<ruleset name="Coding standard">
<description>Coding standard</description>

<!-- display progress -->
<arg value="p"/>
<!-- use colors in output -->
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR12">
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>
</rule>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>
</ruleset>
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="all">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
Loading

0 comments on commit 838c4a4

Please sign in to comment.