Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronjacobson committed Jan 2, 2013
0 parents commit e5991f3
Show file tree
Hide file tree
Showing 15 changed files with 879 additions and 0 deletions.
17 changes: 17 additions & 0 deletions LICENSE
@@ -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/>.

24 changes: 24 additions & 0 deletions README.md
@@ -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/*
19 changes: 19 additions & 0 deletions bin/facter4php
@@ -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);
}
8 changes: 8 additions & 0 deletions bin/phpfacts
@@ -0,0 +1,8 @@
#!/usr/bin/php
<?php
/**
* $ bin/phpfacts
*/
$PATH = dirname(__DIR__).'/lib/facter';

echo `FACTERLIB="$PATH" facter | grep -E "^php"`;
7 changes: 7 additions & 0 deletions composer.json
@@ -0,0 +1,7 @@
{
"autoload": {
"psr-0": {
"FacterPHP": "src/"
}
}
}
674 changes: 674 additions & 0 deletions gpl-3.0.txt

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions lib/facter/bcmath.rb
@@ -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
5 changes: 5 additions & 0 deletions lib/facter/version.rb
@@ -0,0 +1,5 @@
Facter.add(:php_version) do
setcode do
Facter::Util::Resolution.exec('facter4php Version')
end
end
25 changes: 25 additions & 0 deletions phpunit.xml.dist
@@ -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>
30 changes: 30 additions & 0 deletions src/FacterPHP/Fact/BCMath.php
@@ -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';
};
}
}
16 changes: 16 additions & 0 deletions src/FacterPHP/Fact/Version.php
@@ -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();
}
}
17 changes: 17 additions & 0 deletions src/FacterPHP/Facts.php
@@ -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();
}
}
9 changes: 9 additions & 0 deletions src/FacterPHP/Interfaces/FactInterface.php
@@ -0,0 +1,9 @@
<?php

namespace FacterPHP\Interfaces;

interface FactInterface
{
public function __construct($argv);
public function getFact();
}
13 changes: 13 additions & 0 deletions tests/FacterPHP/FacterPHPTest.php
@@ -0,0 +1,13 @@
<?php

namespace FacterPHP\Tests;

class FacterPHPTest extends \PHPUnit_Framework_TestCase
{
public function setUp(){

}
public function testTestName(){

}
}
4 changes: 4 additions & 0 deletions tests/bootstrap.php
@@ -0,0 +1,4 @@
<?php

$loader = require dirname(__DIR__).'/vendor/autoload.php';
$loader->add('FacterPHP\Tests', __DIR__);

0 comments on commit e5991f3

Please sign in to comment.