Skip to content

WIP #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

WIP #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
766 changes: 766 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: php

php:
- 5.3
- 5.4
- 7.2

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev
- curl -s http://getcomposer.org/installer | php
- php composer.phar install

script: phpunit --coverage-text
script: composer run tests
55 changes: 30 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ add appropriate modules from the Linux Kernel:

For *LEDs*, enable the gpio module :

``` bash
$ sudo modprobe w1-gpio
```bash
sudo modprobe w1-gpio
```

([see a complete circuit diagram for a single LED + explanations & schemas here](https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/))

For *sensors*, enable the appropriate sensor.
By example for a [DS18B20 1-Wire digital temperature sensor](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/overview):

``` bash
$ sudo modprobe w1-therm
```bash
sudo modprobe w1-therm
```

([see the DS18B20 in action on a Raspberry Pi here](https://github.com/ronanguilloux/temperature-pi))

To load such kernel modules automatically at boot time, edit the `/etc/modules` file & add these two lines:

```
```text
w1-gpio
w1-therm
```
Expand All @@ -78,23 +78,23 @@ The recommended way to install php-gpio is through [composer](http://getcomposer

Just run these three commands to install it

``` bash
$ sudo apt-get install git
$ wget http://getcomposer.org/composer.phar
$ php composer.phar create-project --stability='dev' ronanguilloux/php-gpio intoYourPath
```bash
sudo apt-get install git
wget http://getcomposer.org/composer.phar
php composer.phar create-project --stability='dev' ronanguilloux/php-gpio intoYourPath
```

Now you can add the autoloader, and you will have access to the library:

``` php
```php
<?php

require 'vendor/autoload.php';
```

If you don't use neither **Composer** nor a _ClassLoader_ in your application, just require the provided autoloader:

``` php
```php
<?php

require_once 'src/autoload.php';
Expand All @@ -107,7 +107,7 @@ API Usage
The API usage requires sudo permissions.
To respect such permissions needs (say, for any web-related usage), see blinker file and the explanations below.

``` php
```php
<?php

require 'vendor/autoload.php';
Expand Down Expand Up @@ -167,8 +167,8 @@ This is the regular linux-file-permission-system way to do such things, not a du

Edit your `/etc/sudoers` file:

``` bash
$ sudo visudo
```bash
sudo visudo
```

Then add this two lines in your `/etc/sudoers` file :
Expand All @@ -183,7 +183,7 @@ The blinker file provided now has the sufficient permissions & is ready to use t

You can test the blinker file solution with the `blinkerTest.php` file provided here:

``` php
```php
<?php

# blinkTester.php
Expand All @@ -194,8 +194,8 @@ $result = exec('sudo -t /usr/bin/php ./blinker 17 20000');

Test your blinker:

``` bash
$ php blinkTester.php
```bash
php blinkTester.php
```


Expand All @@ -214,16 +214,16 @@ Running the full PhpUnit tests set over php-gpio requires a sudoable user, becau
Instead of installing phpunit, you can just download & use the single PhpUnit package.
This can be easily done using `cURL`, to get the standalone PhpUnit's phar file:

``` bash
$ wget http://pear.phpunit.de/get/phpunit.phar
$ chmod +x phpunit.phar
```bash
wget http://pear.phpunit.de/get/phpunit.phar
chmod +x phpunit.phar
```
``` bash
$ wget http://getcomposer.org/composer.phar
$ php composer.phar install --dev
```bash
wget http://getcomposer.org/composer.phar
php composer.phar install --dev
```
``` bash
$ sudo /usr/bin/php phpunit.phar
```bash
sudo /usr/bin/php phpunit.phar
```


Expand All @@ -232,6 +232,11 @@ PHP Quality

For [PHP quality fans](http://phpqatools.org), and for my self coding improvement, I wrote a little script available in the ./bin directory I launch to check my PHP code: It produces various stats & metrics & improvements tips on the code.

Run tests

```bash
composer run tests
```

Credits
-------
Expand Down
14 changes: 7 additions & 7 deletions blinker
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ use PhpGpio\Gpio;
// Am i using php-cli?
if ('cli' != PHP_SAPI) {
echo $msg = "This script must be run using php-cli";
throw new \Exception($msg);
throw new Exception($msg);
}

// Am I a sudoer or the root user?
if ('root' !== $_SERVER['USER'] || empty($_SERVER['SUDO_USER'])) {
echo $msg = "Please run this script as root, using sudo -t ; please check the README file";
throw new \Exception($msg);
throw new Exception($msg);
}

// Am I using only 2 integer arguments ?
if (
!(3 === $argc)
|| (0 >= (int)($argv[1]))
|| (0 >= (int)($argv[2]))
!(3 === $argc)
|| (0 >= (int)($argv[1]))
|| (0 >= (int)($argv[2]))
) {
echo $msg = "This script expect 2 positive integer arguments: please check the README file";
throw new \Exception($msg);
throw new Exception($msg);
}


$pin = (int)$argv[1];
$sleeper = (int)$argv[2];
$gpio = new GPIO();

if(!in_array($pin, $gpio->getHackablePins())){
if (!in_array($pin, $gpio->getHackablePins())) {
echo $msg = "$pin is not a hackable gpio pin number";
throw new \InvalidArgumentException($msg);
}
Expand Down
74 changes: 52 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
{
"name": "ronanguilloux/php-gpio",
"type": "library",
"description": "GPIO-related utils & toolkit PHP library",
"keywords": ["GPIO", "hardware", "chipset", "input", "output", "port", "pin", "chip", "sensors", "raspberry", "raspberry pi"],
"homepage": "https://github.com/ronanguilloux/php-gpio",
"license": "MIT",
"authors": [
{
"name": "Ronan Guilloux",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": { "PhpGpio": "src/" }
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
"name": "ronanguilloux/php-gpio",
"type": "library",
"description": "GPIO-related utils & toolkit PHP library",
"keywords": [
"GPIO",
"hardware",
"chipset",
"input",
"output",
"port",
"pin",
"chip",
"sensors",
"raspberry",
"raspberry pi"
],
"homepage": "https://github.com/ronanguilloux/php-gpio",
"license": "MIT",
"authors": [
{
"name": "Ronan Guilloux",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.0.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.11",
"squizlabs/php_codesniffer": "3.*"
},
"autoload": {
"psr-4": {
"PhpGpio\\": "src/PhpGpio/"
}
},
"autoload-dev": {
"psr-4": {
"PhpGpio\\Test\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"scripts": {
"tests": "phpdbg -qrr vendor/bin/phpunit tests",
"phpcs": "phpcs -ns --report=full",
"phpcs-fix": "phpcbf src tests src",
"phpstan": "phpstan analyse -l 6 --no-progress -n --ansi ./src/"
}
}
33 changes: 33 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<ruleset name="Mehrkanal coding standard">
<description>Mehrkanal coding standard</description>

<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>
<arg name="extensions" value="php,dist,phtml"/>

<!-- inherit rules from: -->
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1"/>
</properties>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="200"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>
<exclude-pattern>tests/integration/assets/*</exclude-pattern>
</ruleset>
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
universalObjectCratesClasses:
- Zend\Stdlib\Parameters
includes:
- vendor/jangregor/phpstan-prophecy/src/extension.neon
19 changes: 19 additions & 0 deletions src/PhpGpio/FileGetContentsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PhpGpio;

class FileGetContentsService
{
/**
* Abstract access to Filesystem for Tests
*
* @param string $path
* @return string
*/
static public function get(string $path): string
{
$result = file_get_contents($path);
return ($result === false) ? '' : $result;
}

}
Loading