Permalink
Browse files

adding heval (command-line Habari evaluator to bootstrap the Habari e…

…nvironment for easier, simple testing

git-svn-id: https://svn.habariproject.org/habari/trunk/scripts@3813 653ae4dd-d31e-0410-96ef-6bf7bf53c507
  • Loading branch information...
Sean Coates
Sean Coates committed Nov 22, 2009
1 parent 1b4213d commit cdd017ba8ee5fbe51f2e209883cfc9dd755afb65
Showing with 47 additions and 6 deletions.
  1. +0 −6 builddocs
  2. +47 −0 heval
View
@@ -1,6 +0,0 @@
-#!/bin/sh
-phpdoc \
- -ti 'Habari PHP API Documentation' \
- -dc 'Habari' \
- -dn 'Habari' \
- -d ./ -t PHPDOCS/
View
47 heval
@@ -0,0 +1,47 @@
+#!/usr/bin/env php
+<?php
+/**
+ * Habari bootstrapped evaluator
+ *
+ * WARNING: DO NOT PUT THIS FILE IN YOUR PUBLIC WEBROOT, OR ANYWHERE ACCESSIBLE
+ * BY YOUR WEB SERVER. PROTECT IT. THIS CODE IS DANGEROUS IN THE WRONG HANDS.
+ *
+ * This script can be used to run code from within the Habari infrastructure
+ * from the command line.
+ *
+ * Example:
+ * $ echo 'echo Format::autop("foo\n\nbar");' | ./heval
+ * <p>foo</p><p>bar</p>
+ *
+ * You may need to change the #! line above, if your system doesn't have `env`
+ * in the normal place.
+ *
+ * Also, if this script can't find your Habari install, try setting
+ * $_ENV['HEVAL_INDEX'] to /path/to/habari/htdocs/index.php
+ *
+ * If you don't know what the #! line is, or how to set $_ENV, you really
+ * shouldn't be using this script. Delete it now.
+ */
+
+if ( 'cli' !== PHP_SAPI ) {
+ echo "For security reasons, this script can only be run from the cli SAPI.\n";
+ die;
+}
+
+$cmd = file_get_contents( 'php://stdin' );
+
+define( 'UNIT_TEST', true );
+if (isset($_ENV['HEVAL_INDEX'])) {
+ require $_ENV['HEVAL_INDEX'];
+} else {
+ require dirname( dirname( __FILE__ ) ) . '/htdocs/index.php';
+}
+
+ob_start();
+eval( $cmd );
+$out = ob_get_clean();
+
+if ( substr( $out, -1 ) != "\n" ) {
+ $out .= "\n";
+}
+echo $out;

0 comments on commit cdd017b

Please sign in to comment.