Skip to content

Commit 67c339e

Browse files
committed
enhancements after having tested the php-gpio lib with the ronanguilloux/php-gpio-web sample implementation
1 parent 5ae8500 commit 67c339e

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

README.md

+5-10
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,19 @@ $ sudo visudo
101101

102102
Then add this two lines in your `/etc/sudoers` file :
103103

104-
``` bash
105-
pi ALL=NOPASSWD: /path/to/blinker
106-
www-data ALL=NOPASSWD: /path/to/blinker
107104
```
108-
109-
Note that you could also have written more pathes:
110-
111-
``` bash
112-
myLinuxLogin ALL=NOPASSWD: /path/to/blinker1.php, /path/to/blinker2.php, /path/to/blinker3.php
105+
www-data ALL=NOPASSWD:/path/to/the/blinker
113106
```
114107

115-
The blinker file provided is ready to use the API. Just create a blinkTester.php file that calls the blinker.
108+
Replace /pat/to/the/blinker with your project path
109+
110+
The blinker file provided is ready to use the API. You do not need to install apache2-suexec nor suPHP.
116111

117112
``` php
118113
<?php
119114

120115
# blinkTester.php
121-
116+
122117
# Blinks the LED wired to the GPIO #17 pin with 0.2 second delay:
123118
$result = exec('sudo ./blinker 17 20000');
124119
```

blinker

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ use PhpGpio\Gpio;
1313

1414
// Am i using php-cli?
1515
if ('cli' != PHP_SAPI) {
16-
throw new \Exception("This script must be run using php-cli");
16+
echo $msg = "This script must be run using php-cli";
17+
throw new \Exception($msg);
1718
}
1819

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

24-
// Am I using only 2 integer arugments ?
26+
// Am I using only 2 integer arguments ?
2527
if (
2628
!(3 === $argc)
2729
|| (0 >= (int)($argv[1]))
2830
|| (0 >= (int)($argv[2]))
2931
) {
30-
throw new \Exception("This script expect 2 positive integer arguments: please check the README file");
32+
echo $msg = "This script expect 2 positive integer arguments: please check the README file";
33+
throw new \Exception($msg);
3134
}
3235

3336

@@ -36,7 +39,8 @@ $sleeper = (int)$argv[2];
3639
$gpio = new GPIO();
3740

3841
if(!in_array($pin, $gpio->getHackablePins())){
39-
throw new \InvalidArgumentException("$pin is not a hackable gpio pin number");
42+
echo $msg = "$pin is not a hackable gpio pin number";
43+
throw new \InvalidArgumentException($msg);
4044
}
4145

4246
$gpio->setup($pin, "out");

0 commit comments

Comments
 (0)