Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoreram committed Dec 30, 2019
0 parents commit 3070d4d
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
end_of_line = LF

[*.php]
indent_style = space
indent_size = 4
18 changes: 18 additions & 0 deletions .formatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use-sort:
group:
- _main
group-type: each
sort-type: alph
sort-direction: asc
strict: true
header: |
/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor
.php_cs.cache
composer.lock
var
16 changes: 16 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('var')
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'single_line_after_imports' => false,
'no_superfluous_phpdoc_tags' => false
])
->setFinder($finder)
;
46 changes: 46 additions & 0 deletions 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/
19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) Marc Morera <[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.
73 changes: 73 additions & 0 deletions OutputPrinter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace Drift\Console;

use Symfony\Component\Console\Output\OutputInterface;

/**
* Class ServerHeaderPrinter.
*/
class OutputPrinter
{
/**
* @var OutputInterface
*/
private $output;

/**
* ServerHeaderPrinter constructor.
*
* @param OutputInterface $output
*/
public function __construct(OutputInterface $output)
{
$this->output = $output;
}

/**
* Print header line.
*
* @param string $line
*/
public function printHeaderLine(string $line = '')
{
$this->printLine("> $line");
}

/**
* Print line.
*
* @param string $line
*/
public function printLine(string $line = '')
{
$this
->output
->writeln($line);
}

/**
* Print line.
*
* @param string $data
*/
public function print(string $data)
{
$this
->output
->write($data);
}
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# DriftPHP Console Bridge

This package provides a bridge between DriftPHP and the Symfony Console
component, adding some formatted objects to use in some components

Some first steps for you!

- [Go to DOCS](https://driftphp.io/#/?id=the-server)

or

- [Try a demo](https://github.com/driftphp/demo)
- [Install the skeleton](https://github.com/driftphp/skeleton)
34 changes: 34 additions & 0 deletions Tests/TimeFormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace Drift\Server\Tests;

use Drift\Console\TimeFormatter;
use PHPUnit\Framework\TestCase;

/**
* Class TimeFormatterTest.
*/
class TimeFormatterTest extends TestCase
{
/**
* Test format time.
*/
public function testFormatTime()
{
$this->assertEquals('10 ms', TimeFormatter::formatTime(0.010));
$this->assertEquals('300 μs', TimeFormatter::formatTime(0.000300));
}
}
40 changes: 40 additions & 0 deletions TimeFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace Drift\Console;

/**
* Class TimeFormatter.
*/
class TimeFormatter
{
/**
* Format time in milliseconds.
*
* @param float $timeInSeconds
*
* @return string
*/
public static function formatTime(float $timeInSeconds): string
{
$timeInMicroseconds = \intval($timeInSeconds * 1000000);

if ($timeInMicroseconds >= 1000) {
return \intval($timeInMicroseconds / 1000).' ms';
}

return "$timeInMicroseconds μs";
}
}
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "drift/console-bridge",
"description": "Console bridge for DriftPHP",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Marc Morera",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.3",

"symfony/console": "^5.0"
},
"autoload": {
"psr-4": {
"Drift\\Console\\": "."
}
}
}

0 comments on commit 3070d4d

Please sign in to comment.