mirror of
https://github.com/n3w/helpers-functions-cli.git
synced 2025-12-19 12:43:22 +00:00
Initial commit
This commit is contained in:
commit
a34ef4419e
7 changed files with 185 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
vendor/
|
||||||
|
composer.lock
|
||||||
|
.DS_Store
|
||||||
|
.php_cs.cache
|
||||||
12
CHANGELOG.md
Normal file
12
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
# Change Log
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
**View all [Unreleased][] changes here**
|
||||||
|
|
||||||
|
## 1.0.0
|
||||||
|
#### Added
|
||||||
|
- Initial release
|
||||||
|
|
||||||
|
[Unreleased]: https://github.com/pointybeard/helpers-functions-cli/compare/1.0.0...integration
|
||||||
19
CONTRIBUTING.md
Normal file
19
CONTRIBUTING.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Contributing to this project
|
||||||
|
|
||||||
|
We encourage contribution to this project and only ask you follow some simple rules to make everyone's job a little easier.
|
||||||
|
|
||||||
|
## Found a bug?
|
||||||
|
|
||||||
|
Please lodge an issue at the GitHub issue tracker for this project -- [https://github.com/pointybeard/helpers-functions-cli/issues](https://github.com/pointybeard/helpers-functions-cli/issues)
|
||||||
|
|
||||||
|
Include details on the behaviour you are seeing, and steps needed to reproduce the problem.
|
||||||
|
|
||||||
|
## Want to contribute code?
|
||||||
|
|
||||||
|
* Fork the project
|
||||||
|
* Make your feature addition or bug fix
|
||||||
|
* Ensure your code is nicely formatted
|
||||||
|
* Commit just the modifications, do not alter CHANGELOG.md. If relevant, link to GitHub issue (see [https://help.github.com/articles/closing-issues-via-commit-messages/](https://help.github.com/articles/closing-issues-via-commit-messages/))
|
||||||
|
* Send the pull request
|
||||||
|
|
||||||
|
We will review the code and either merge it in, or leave some feedback.
|
||||||
26
LICENCE
Normal file
26
LICENCE
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
All source code included in the "PHP Helpers: Command-line Functions" archive is,
|
||||||
|
unless otherwise specified, released under the MIT licence as follows:
|
||||||
|
|
||||||
|
----- begin license block -----
|
||||||
|
|
||||||
|
Copyright 2019 Alannah Kearney
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
----- end license block -----
|
||||||
61
README.md
Normal file
61
README.md
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
# PHP Helpers: Command-line Functions
|
||||||
|
|
||||||
|
- Version: v1.0.0
|
||||||
|
- Date: May 08 2019
|
||||||
|
- [Release notes](https://github.com/pointybeard/helpers-functions-cli/blob/master/CHANGELOG.md)
|
||||||
|
- [GitHub repository](https://github.com/pointybeard/helpers-functions-cli)
|
||||||
|
|
||||||
|
A collection of functions relating to the command-line
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
This library is installed via [Composer](http://getcomposer.org/). To install, use `composer require pointybeard/helpers-functions-cli` or add `"pointybeard/helpers-functions-cli": "~1.0"` to your `composer.json` file.
|
||||||
|
|
||||||
|
And run composer to update your dependencies:
|
||||||
|
|
||||||
|
$ curl -s http://getcomposer.org/installer | php
|
||||||
|
$ php composer.phar update
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
There are no particuar requirements for this library other than PHP 5.6 or greater.
|
||||||
|
|
||||||
|
To include all the [PHP Helpers](https://github.com/pointybeard/helpers) packages on your project, use `composer require pointybeard/helpers` or add `"pointybeard/helpers": "~1.0"` to your composer file.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
This library is a collection convenience function for common tasks relating to bitwise flags. They are included by the vendor autoloader automatically. The functions have a namespace of `pointybeard\Helpers\Functions\Cli`
|
||||||
|
|
||||||
|
The following functions are provided:
|
||||||
|
|
||||||
|
- `can_invoke_bash() : bool`
|
||||||
|
- `is_su() : bool`
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
include __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
use pointybeard\Helpers\Functions\Cli;
|
||||||
|
|
||||||
|
var_dump(Cli\can_invoke_bash());
|
||||||
|
// bool(true)
|
||||||
|
|
||||||
|
var_dump(Cli\is_su());
|
||||||
|
// bool(false)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/pointybeard/helpers-functions-cli/issues),
|
||||||
|
or better yet, fork the library and submit a pull request.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
We encourage you to contribute to this project. Please check out the [Contributing documentation](https://github.com/pointybeard/helpers-functions-cli/blob/master/CONTRIBUTING.md) for guidelines about how to get involved.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
"PHP Helpers: Command-line Functions" is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
||||||
32
composer.json
Normal file
32
composer.json
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
"name": "pointybeard/helpers-functions-cli",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A collection of functions relating to the command-line",
|
||||||
|
"homepage": "https://github.com/pointybeard/helpers-functions-cli",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Alannah Kearney",
|
||||||
|
"email": "hi@alannahkearney.com",
|
||||||
|
"homepage": "http://alannahkearney.com",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.6.6"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^5",
|
||||||
|
"block8/php-docblock-checker": "~1.10"
|
||||||
|
},
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/pointybeard/helpers-functions-cli/issues",
|
||||||
|
"wiki": "https://github.com/pointybeard/helpers-functions-cli/wiki"
|
||||||
|
},
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/Cli/Cli.php"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/Cli/Cli.php
Normal file
31
src/Cli/Cli.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace pointybeard\Helpers\Functions\Cli;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if bash can be invoked.
|
||||||
|
*
|
||||||
|
* Credit to Troels Knak-Nielsen for inspiring this code.
|
||||||
|
* (http://www.sitepoint.com/interactive-cli-password-prompt-in-php/)
|
||||||
|
*
|
||||||
|
* @return bool true if bash can be invoked
|
||||||
|
*/
|
||||||
|
if (!function_exists(__NAMESPACE__ . 'can_invoke_bash')) {
|
||||||
|
function can_invoke_bash()
|
||||||
|
{
|
||||||
|
return (strcmp(trim(shell_exec("/usr/bin/env bash -c 'echo OK'")), 'OK') === 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if script is running as root user
|
||||||
|
*
|
||||||
|
* @return bool true if user is root
|
||||||
|
*/
|
||||||
|
if (!function_exists(__NAMESPACE__ . 'is_su')) {
|
||||||
|
function is_su()
|
||||||
|
{
|
||||||
|
$userinfo = posix_getpwuid(posix_geteuid());
|
||||||
|
return (bool)($userinfo['uid'] == 0 || $userinfo['name'] == 'root');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue