Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e5991f3
Showing
15 changed files
with
879 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FacterPHP - PHP Facts for PuppetLabs Facter | ||
|
||
Copyright (C) 2013 Cameron Jacobson | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# FacterPHP | ||
|
||
A way to populate PuppetLabs Facter with PHP facts. | ||
|
||
There are 2 symlinks you'll need to set: | ||
|
||
### First: | ||
* bin/facter4php needs to be in $PATH | ||
$ sudo ln -s $PWD/bin/facter4php /usr/local/bin | ||
|
||
### Second (Optional): | ||
* bin/phpfacts can be in $PATH | ||
$ sudo ln -s $PWD/bin/phpfacts /usr/local/bin | ||
|
||
### Third: | ||
* ./facts needs to be linked to applicable puppet module | ||
$ ln -s $PWD/lib/facter /usr/local/etc/puppet/{modulepath}/{module}/lib/facter | ||
|
||
### To test your facts: | ||
- bin/loadfacts | ||
|
||
## see examples in: | ||
|
||
examples/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/php | ||
<?php | ||
/** | ||
* Usage: $ bin/facter4php {factname} | ||
* | ||
* See lib/facter/* or src/FacterPHP/Fact/* for possible {factname} values | ||
*/ | ||
define('FACTER_PHP_DIR',dirname(__DIR__)); | ||
|
||
require_once(FACTER_PHP_DIR.'/vendor/autoload.php'); | ||
|
||
use FacterPHP\Facts as PhpFact; | ||
|
||
try{ | ||
$fact = new PhpFact($argv); | ||
echo $fact->getFact(); | ||
} catch(\Exception $e){ | ||
file_put_contents('php://stderr', 'ERROR: '.$e->getMessage().PHP_EOL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/php | ||
<?php | ||
/** | ||
* $ bin/phpfacts | ||
*/ | ||
$PATH = dirname(__DIR__).'/lib/facter'; | ||
|
||
echo `FACTERLIB="$PATH" facter | grep -E "^php"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"autoload": { | ||
"psr-0": { | ||
"FacterPHP": "src/" | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Facter.add(:php_bcmath_installed) do | ||
setcode do | ||
Facter::Util::Resolution.exec('facter4php BCMath installed') | ||
end | ||
end | ||
|
||
Facter.add(:php_bcmath_somethingelse) do | ||
setcode do | ||
Facter::Util::Resolution.exec('facter4php BCMath somethingelse') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Facter.add(:php_version) do | ||
setcode do | ||
Facter::Util::Resolution.exec('facter4php Version') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
bootstrap="tests/bootstrap.php" | ||
> | ||
<testsuites> | ||
<testsuite name="FacterPHP Test Suite"> | ||
<directory>./tests/FacterPHP/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace FacterPHP\Fact; | ||
|
||
use \FacterPHP\Interfaces\FactInterface; | ||
|
||
class BCMath implements FactInterface | ||
{ | ||
protected $callable; | ||
|
||
public function __construct($argv){ | ||
switch($argv[2]){ | ||
case 'installed': | ||
$this->callable = $this->isInstalled(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
public function getFact(){ | ||
return empty($this->callable) ? 'unknown' : call_user_func($this->callable); | ||
} | ||
|
||
public function isInstalled(){ | ||
return function(){ | ||
return function_exists('bcadd') ? 'yes' : 'no'; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace FacterPHP\Fact; | ||
|
||
use \FacterPHP\Interfaces\FactInterface; | ||
|
||
class Version implements FactInterface | ||
{ | ||
public function __construct($argv){ | ||
|
||
} | ||
|
||
public function getFact(){ | ||
return phpversion(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace FacterPHP; | ||
|
||
class Facts | ||
{ | ||
protected $fact; | ||
|
||
public function __construct($argv){ | ||
$class = 'FacterPHP\Fact\\'.$argv[1]; | ||
$this->fact = new $class($argv); | ||
} | ||
|
||
public function getFact(){ | ||
return $this->fact->getFact(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace FacterPHP\Interfaces; | ||
|
||
interface FactInterface | ||
{ | ||
public function __construct($argv); | ||
public function getFact(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace FacterPHP\Tests; | ||
|
||
class FacterPHPTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setUp(){ | ||
|
||
} | ||
public function testTestName(){ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
$loader = require dirname(__DIR__).'/vendor/autoload.php'; | ||
$loader->add('FacterPHP\Tests', __DIR__); |