Example #1
0
 /**
  * Run ZMQ interface for generator
  * 
  * Req-rep pattern; msgs are commands:
  * 
  * GEN    = Generate ID
  * STATUS = Get status string
  */
 public function run()
 {
     $context = new \ZMQContext();
     $receiver = new \ZMQSocket($context, \ZMQ::SOCKET_REP);
     $bindTo = 'tcp://*:' . $this->port;
     echo "Binding to {$bindTo}\n";
     $receiver->bind($bindTo);
     while (TRUE) {
         $msg = $receiver->recv();
         switch ($msg) {
             case 'GEN':
                 try {
                     $response = $this->generator->generate();
                 } catch (\Exception $e) {
                     $response = "ERROR";
                 }
                 break;
             case 'STATUS':
                 $response = json_encode($this->generator->status());
                 break;
             default:
                 $response = 'UNKNOWN COMMAND';
                 break;
         }
         $receiver->send($response);
     }
 }
Example #2
0
 /**
  * Generating UUID should return different results every time
  *
  * @covers Mixpanel\Uuid\Generator::generate
  * @covers Mixpanel\Uuid\Generator::ticksEntropy
  * @covers Mixpanel\Uuid\Generator::uaEntropy
  * @covers Mixpanel\Uuid\Generator::randomEntropy
  * @covers Mixpanel\Uuid\Generator::ipEntropy
  */
 public function testGeneratingUuidShouldReturnDifferentResultEveryTime()
 {
     $uuids = array();
     for ($i = 0; $i < 100; $i++) {
         $uuid = $this->generator->generate('user-agent', '127.0.0.1');
         $this->assertNotContains($uuid, $uuids);
         $uuids[] = $uuid;
     }
 }
Example #3
0
 /**
  * Creates accessor for instances of given class.
  * @param string $class
  * @return Accessor
  */
 public function create($class)
 {
     $name = $this->naming->deriveClassName($class);
     $namespaced = $this->naming->getNamespace() . '\\' . $name;
     if (class_exists($namespaced) || $this->cache && $this->cache->load($name)) {
         return new $namespaced();
     }
     $definition = $this->generator->generate($class);
     if ($this->cache) {
         $this->cache->save($name, $definition);
     }
     eval($definition);
     return new $namespaced();
 }
 /**
  * Generates XML code
  * @throws FeedGeneratorException
  */
 public function generate()
 {
     if (!$this->_generator instanceof Generator) {
         throw new FeedGeneratorException('There has been no generator strategy set.');
     }
     $this->generated = $this->_generator->generate($this->_channel);
 }
 public function generateSql()
 {
     $namespace = \Zule\Tools\Config::zc()->framework->application_namespace;
     $system = 'Zule';
     $tables = $this->settings->getTables();
     foreach ($tables as $table) {
         $s = new \Smarty();
         $tableName = $table->getName();
         // generate model
         $s->assign('model_name', $_POST["class_{$tableName}"]);
         $s->assign('namespace', $namespace);
         $s->assign('system', $system);
         $s->assign('class_name', $_POST["class_{$tableName}"]);
         $s->assign('extend_path', '\\Zule\\Models\\Model');
         $s->assign('impl_date', date('Y-m-d H:i:s'));
         $s->assign('use_unsafe_setters', 0);
         $s->assign('table_name', $tableName);
         $columns = $table->getColumns();
         $s->assign('columns', $columns);
         $s->assign('primary_key', $table->getPrimaryKey());
         $gen = new Generator("../models/" . $_POST["class_{$tableName}"] . '.php');
         $gen->generate($s, 'model_sql');
         $gen = new Generator("../models/Data/" . $_POST["class_{$tableName}"] . '.php');
         $gen->generate($s, 'gateway_sql');
     }
 }
Example #6
0
 function execute()
 {
     $generator_class = $this->generator_class;
     foreach ($this->values as $index => $value) {
         Generator::generate($value, new $generator_class($value, $this->parent, $this->args));
     }
 }
function main()
{
    $args = \Docopt::handle(<<<s
A PHP class autoload generator with support for functions and constants.

Example:

    generate-autoload src/autoload.php

        Will write an autoloader for everything in "src/" to "src/autoload.php".

    generate-autoload autoload.php src --exclude src/Bar lib/functions.php

        Will write to an autoloader for everything in "src/" and
        "lib/functions.php", except for everything in "src/Bar", to "autoload.php".

Usage:
    generate-autoload [options] <outfile> [<files>...] [--exclude <file>]...
    generate-autoload -h|--help

Options:
    --require-method=<method>  One of "include", "require", "include_once" or
                               "require_once". [default: require_once]
    --case-insensitive         Autoload classes case insensitively. Will involve
                               a strtolower() call every time a class is loaded.
    --prepend                  Third parameter to spl_autoload_register().
    --exclude <file>           Exclude a file/directory.

s
);
    $outFile = $args['<outfile>'];
    $files = array_diff(iterator_to_array(flatten_input_paths($args['<files>'] ?: [dirname($outFile)])), iterator_to_array(flatten_input_paths($args['--exclude'])));
    global $argv;
    $options = new GeneratorOptions();
    $options->requireMethod = $args['--require-method'];
    $options->prependAutoload = $args['--prepend'];
    $options->caseInsensitive = $args['--case-insensitive'];
    $options->generatedBy = join(' ', $argv);
    $generator = new Generator();
    foreach ($files as $file) {
        print "Scanning {$file}\n";
        $generator->addFile($file);
    }
    print "\n";
    file_put_contents($outFile, $generator->generate(dirname($outFile), $options));
    print "Output written to {$outFile}\n";
}
Example #8
0
 public static function main($e)
 {
     $io = $e->getIO();
     $args = $e->getArguments();
     $command = @$args[0];
     switch ($command) {
         case 'generate':
             $arg2 = @$args[1];
             if (!$arg2) {
                 $io->writeError('ERROR: You must provide a directory to generate the style guide');
             } else {
                 $generator = new Generator($io);
                 $generator->generate($arg2);
             }
             break;
         default:
             $io->write(self::$usage . PHP_EOL);
             break;
     }
 }
Example #9
0
                    <small class="notice">Tables in red have been previously created</small>
                    
                    <label class="checkbox inline">
                        <input type="checkbox" id="inputBackup" name="backup" value="1" checked /> Enable automatic backup of models
                    </label>
                </div>
            </div>
            
            <br />
            <input type="button" value="BACK" class="btn btn-primary" onclick="javascript:history.back()" />
            <input type="submit" value="NEXT" class="btn btn-primary" />
        </fildset>
    </form>

    <?php 
    exit;
}
//***************************************************
// STEP 3
//***************************************************
// Enable automatic backup of models
$backup = isset($_POST['backup']) ? (bool) $_POST['backup'] : null;
$database = isset($_POST['database']) ? $_POST['database'] : null;
$tables = isset($_POST['tables']) ? (array) $_POST['tables'] : null;
Generator::setBackup($backup);
Generator::generate($database, $tables);
echo '<br /><input type="button" value="FINISH" class="btn btn-primary" onclick="javascript:history.go(-2);" /><br /><br /><br /><br />';
?>
</div>
</body>
</html>
Example #10
0
}
if ($cli->getValue('--xsiArrayType')) {
    $optionsArray[] = 'SOAP_USE_XSI_ARRAY_TYPE';
}
if ($cli->getValue('--waitOneWayCalls')) {
    $optionsArray[] = 'SOAP_WAIT_ONE_WAY_CALLS';
}
$wsdlCache = '';
if ($cli->getValue('--cacheNone')) {
    $wsdlCache = 'WSDL_CACHE_NONE';
} else {
    if ($cli->getValue('--cacheDisk')) {
        $wsdlCache = 'WSDL_CACHE_DISK';
    } else {
        if ($cli->getValue('--cacheMemory')) {
            $wsdlCache = 'WSDL_CACHE_MEMORY';
        } else {
            if ($cli->getValue('--cacheBoth')) {
                $wsdlCache = 'WSDL_CACHE_BOTH';
            }
        }
    }
}
$gzip = '';
if ($cli->getValue('--gzip')) {
    $gzip = 'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP';
}
$config = new Config($inputFile, $outputDir, $verbose, $singleFile, $classExists, $noTypeConstructor, $namespaceName, $optionsArray, $wsdlCache, $gzip, $classNames, $prefix, $suffix);
$generator = new Generator();
$generator->generate($config);
Example #11
0
// Should we add the year to the title (eh: PyCon11 or PyCon2011 instead of PyCon?)
define("EVENT_ADD_YEAR_TO_TITLE", 10);
// 50% chance if the additional year added to the name is a full year (2011) instead of short year (11)
define("EVENT_ADD_FULLYEAR_TO_TITLE", 50);
// Percentage of anonymous comments on events
define("EVENT_COMMENT_IS_ANONYMOUS", 15);
// Percentage of anonymous comments on talks
define("TALK_COMMENT_IS_ANONYMOUS", 15);
// 5% of the comments are marked private
define("COMMENT_IS_PRIVATE", 5);
// Percentage of talks that is claimed
define("TALK_IS_CLAIMED", 75);
// Does the talk have multiple speakers
define("TALK_HAS_MULTIPLE_SPEAKERS", 20);
// Percentage of the talks that have slides associated with them
define("TALK_HAS_SLIDES", 35);
// Amount of claims that are still pending
define("TALK_SPEAKER_PENDING", 10);
// Percentage of talks that is claimed by a user that has registered through joind.in
define("TALK_IS_CLAIMED_BY_REGISTERED_USER", 75);
// Only 1 percent of the users is an admin
define("USER_IS_ADMIN", 1);
// 25% has a twitter account
define("USER_HAS_TWITTER", 25);
// ====================== NOTHING TO EDIT BELOW THIS POINT, MOVE ALONG ======================
require_once "generator_data.interface.php";
require_once "generator_data.class.php";
require_once "generator.class.php";
$gen = new Generator(new Generator_Data());
echo $gen->generate();
exit;
 /**
  * AjaxRequest objects are automatically processed when they are created, based on the unique $action
  * value. The result of the call is stored in $response to be handled however you need (e.g. output
  * as JSON, XML etc) - or an Exception is thrown if something went wrong. Exceptions are used SOLELY for
  * program errors: not for user-entry errors.
  */
 public function __construct($action, $post = array())
 {
     if (empty($action)) {
         throw new Exception("no_action_specified");
         return;
     }
     $this->action = $action;
     $post = Utils::sanitize($post);
     switch ($this->action) {
         // ------------------------------------------------------------------------------------
         // INSTALLATION
         // ------------------------------------------------------------------------------------
         // a fresh install assumes it's a blank slate: no database tables, no settings file
         case "installationTestDbSettings":
             Core::init("installation");
             list($success, $content) = Database::testDbSettings($post["dbHostname"], $post["dbName"], $post["dbUsername"], $post["dbPassword"]);
             $this->response["success"] = $success;
             $this->response["content"] = $content;
             break;
         case "installationCreateSettingsFile":
             Core::init("installation");
             if (Core::checkSettingsFileExists()) {
                 $this->response["success"] = 0;
                 $this->response["content"] = "Your settings.php file already exists.";
                 return;
             } else {
                 list($success, $content) = Installation::createSettingsFile($post["dbHostname"], $post["dbName"], $post["dbUsername"], $post["dbPassword"], $post["dbTablePrefix"]);
                 $this->response["success"] = $success;
                 $this->response["content"] = $content;
             }
             break;
         case "installationCreateDatabase":
             Core::init("installation_db_ready");
             list($success, $content) = Installation::createDatabase();
             if (!$success) {
                 $this->response["success"] = 0;
                 $this->response["content"] = $content;
                 return;
             }
             // always create the administrator account. If the user chose the anonymous setup, all values
             // will be blank and all configurations will be associated with this (anonymous) user
             $adminAccount = array("accountType" => "admin", "firstName" => $post["firstName"], "lastName" => $post["lastName"], "email" => $post["email"], "password" => $post["password"]);
             Account::createAccount($adminAccount);
             // make note of the fact that we've passed this installation step
             Settings::setSetting("userAccountSetup", $post["userAccountSetup"]);
             Settings::setSetting("installationStepComplete_Core", "yes");
             $this->response["success"] = 1;
             $this->response["content"] = "";
             break;
         case "installationDataTypes":
             Core::init("installation_db_ready");
             $index = $post["index"];
             $groupedDataTypes = DataTypePluginHelper::getDataTypePlugins("installion_db_ready", false);
             $dataTypes = DataTypePluginHelper::getDataTypeList($groupedDataTypes);
             if ($index >= count($dataTypes)) {
                 $this->response["success"] = 1;
                 $this->response["content"] = "";
                 $this->response["isComplete"] = true;
             } else {
                 // attempt to install this data type
                 $currDataType = $dataTypes[$index];
                 $this->response["dataTypeName"] = $currDataType->getName();
                 $this->response["dataTypeFolder"] = $currDataType->folder;
                 $this->response["isComplete"] = false;
                 try {
                     list($success, $content) = $currDataType->install();
                     $this->response["success"] = $success;
                     $this->response["content"] = $content;
                 } catch (Exception $e) {
                     $this->response["success"] = false;
                     $this->response["content"] = "Unknown error.";
                 }
             }
             break;
         case "installationSaveDataTypes":
             Core::init("installation_db_ready");
             $folders = $post["folders"];
             $response = Settings::setSetting("installedDataTypes", $folders);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["errorMessage"];
             break;
         case "installationExportTypes":
             Core::init("installation_db_ready");
             $index = $post["index"];
             $exportTypes = ExportTypePluginHelper::getExportTypePlugins("installation_db_ready", false);
             if ($index >= count($exportTypes)) {
                 $this->response["success"] = 1;
                 $this->response["content"] = "";
                 $this->response["isComplete"] = true;
             } else {
                 // attempt to install this data type
                 $currExportType = $exportTypes[$index];
                 $this->response["exportTypeName"] = $currExportType->getName();
                 $this->response["exportTypeFolder"] = $currExportType->folder;
                 $this->response["isComplete"] = false;
                 try {
                     list($success, $content) = $currExportType->install();
                     $this->response["success"] = $success;
                     $this->response["content"] = $content;
                 } catch (Exception $e) {
                     $this->response["success"] = false;
                     $this->response["content"] = "Unknown error.";
                 }
             }
             break;
         case "installationSaveExportTypes":
             Core::init("installation_db_ready");
             $folders = $post["folders"];
             $response = Settings::setSetting("installedExportTypes", $folders);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["errorMessage"];
             break;
         case "installationCountries":
             Core::init("installation_db_ready");
             $index = $post["index"];
             $countryPlugins = CountryPluginHelper::getCountryPlugins(false);
             if ($index >= count($countryPlugins)) {
                 $this->response["success"] = 1;
                 $this->response["content"] = "";
                 $this->response["isComplete"] = true;
             } else {
                 // attempt to install this data type
                 $currCountryPlugin = $countryPlugins[$index];
                 $this->response["countryName"] = $currCountryPlugin->getName();
                 $this->response["countryFolder"] = $currCountryPlugin->folder;
                 $this->response["isComplete"] = false;
                 try {
                     // always run the uninstallation function first to ensure any old data is all cleared out
                     $currCountryPlugin->uninstall();
                     list($success, $content) = $currCountryPlugin->install();
                     $this->response["success"] = $success;
                     $this->response["content"] = $content;
                 } catch (Exception $e) {
                     $this->response["success"] = false;
                     $this->response["content"] = "Unknown error.";
                 }
             }
             break;
         case "installationSaveCountries":
             Core::init("installation_db_ready");
             $folders = $post["folders"];
             $response = Settings::setSetting("installedCountries", $folders);
             $response = Settings::setSetting("installationComplete", "yes");
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["errorMessage"];
             break;
         case "generateInPage":
             Core::init("generation");
             $gen = new Generator($_POST);
             $response = $gen->generate();
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["content"];
             $this->response["isComplete"] = $response["isComplete"];
             break;
             // ------------------------------------------------------------------------------------
             // USER ACCOUNTS
             // ------------------------------------------------------------------------------------
         // ------------------------------------------------------------------------------------
         // USER ACCOUNTS
         // ------------------------------------------------------------------------------------
         case "getAccount":
             Core::init();
             $response = Core::$user->getAccount();
             $this->response["success"] = true;
             $this->response["content"] = $response;
             break;
         case "getUsers":
             Core::init();
             $response = Core::$user->getUsers();
             $this->response["success"] = $response["success"];
             if (isset($response["accounts"])) {
                 $this->response["content"] = $response["accounts"];
             }
             break;
         case "createAccount":
             Core::init();
             if (!Core::checkIsLoggedIn()) {
                 $this->response["success"] = false;
                 $this->response["errorCode"] = ErrorCodes::NOT_LOGGED_IN;
             } else {
                 if (Core::$user->getAccountType() != "admin") {
                     $this->response["success"] = false;
                     $this->response["errorCode"] = ErrorCodes::NON_ADMIN;
                 } else {
                     $accountInfo = $post;
                     $accountInfo["accountType"] = "user";
                     $response = Account::createAccount($accountInfo);
                     $this->response["success"] = true;
                 }
             }
             break;
         case "deleteAccount":
             Core::init();
             if (!Core::checkIsLoggedIn()) {
                 $this->response["success"] = false;
                 $this->response["errorCode"] = ErrorCodes::NOT_LOGGED_IN;
             } else {
                 if (Core::$user->getAccountType() != "admin") {
                     $this->response["success"] = false;
                     $this->response["errorCode"] = ErrorCodes::NON_ADMIN;
                 } else {
                     $accountID = $post["accountID"];
                     $response = Core::$user->deleteAccount($accountID);
                     $this->response["success"] = true;
                 }
             }
             break;
             // updates the current logged in user's info
         // updates the current logged in user's info
         case "updateAccount":
             Core::init();
             if (!Core::checkIsLoggedIn()) {
                 $this->response["success"] = false;
                 $this->response["errorCode"] = ErrorCodes::NOT_LOGGED_IN;
             } else {
                 if (Core::$user->isAnonymous()) {
                     $this->response["success"] = false;
                     $this->response["errorCode"] = ErrorCodes::INVALID_REQUEST;
                 } else {
                     $accountID = $post["accountID"];
                     $this->response = Core::$user->updateAccount($accountID, $post);
                 }
             }
             break;
         case "saveConfiguration":
             Core::init();
             $response = Core::$user->saveConfiguration($post);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["message"];
             if (isset($response["lastUpdated"])) {
                 $this->response["lastUpdated"] = $response["lastUpdated"];
             }
             break;
         case "deleteDataSets":
             Core::init();
             $configurationIDs = $post["configurationIDs"];
             $response = Core::$user->deleteConfigurations($configurationIDs);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["message"];
             break;
         case "saveDataSetVisibilityStatus":
             Core::init();
             $configurationID = $post["configurationID"];
             $status = $post["status"];
             $time = $post["time"];
             $response = Core::$user->saveDataSetVisibilityStatus($configurationID, $status, $time);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["message"];
             if (isset($response["newStatus"])) {
                 $this->response["newStatus"] = $response["newStatus"];
             }
             break;
         case "getPublicDataSet":
             Core::init();
             $configurationID = $post["dataSetID"];
             $response = Core::$user->getPublicDataSet($configurationID);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["message"];
             break;
         case "login":
             Core::init();
             $email = $post["email"];
             $password = $post["password"];
             $response = Account::login($email, $password);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["message"];
             break;
             // for single
         // for single
         case "logout":
             Core::init();
             if (!Core::checkIsLoggedIn()) {
                 $this->response["success"] = true;
             } else {
                 if (!Core::$user->isAnonymous()) {
                     Core::$user->logout();
                     $this->response["success"] = true;
                 }
             }
             break;
         case "resetPassword":
             Core::init();
             $email = $post["email"];
             $response = Account::resetPassword($email);
             $this->response["success"] = $response["success"];
             $this->response["content"] = $response["message"];
             break;
     }
 }
Example #13
0
/**
 * Generates Markdown from JSDoc entries in a given file.
 *
 * @param {Array} [$options=array()] The options array.
 * @returns {String} The generated Markdown.
 * @example
 *
 * // specify a file path
 * $markdown = docdown(array(
 *   // path to js file
 *   'path' => $filepath,
 *   // url used to reference line numbers in code
 *   'url' => 'https://github.com/username/project/blob/master/my.js'
 * ));
 *
 * // or pass raw js
 * $markdown = docdown(array(
 *   // raw JavaScript source
 *   'source' => $rawJS,
 *   // documentation title
 *   'title' => 'My API Documentation',
 *   // url used to reference line numbers in code
 *   'url' => 'https://github.com/username/project/blob/master/my.js'
 * ));
 */
function docdown($options = array())
{
    $gen = new Generator($options);
    return $gen->generate();
}
 public function getAllKnown()
 {
     $allDoctypes = array();
     foreach ($this->knownMatrix as $category => $instances) {
         foreach ($instances as $instance) {
             $parentCategory = $category;
             $key = $parentCategory . '-' . str_replace('.', '', $instance['version']);
             $module = null;
             $generator = new Generator();
             if ($this->multiline === true) {
                 $generator->multiline();
             }
             if ($this->noUri === true) {
                 $generator->noUri();
             }
             if ($this->lowercasePrefix === true) {
                 $generator->lowercasePrefix();
             }
             if ($this->lowercaseFpi === true) {
                 $generator->lowercaseFpi();
             }
             if ($this->uppercaseFpi === true) {
                 $generator->uppercaseFpi();
             }
             if ($this->isModuleCategory($parentCategory)) {
                 $module = $this->getModuleFromCategory($parentCategory);
                 $parentCategory = $this->getParentCategoryFromModuleCategory($parentCategory);
             }
             $generator->{$parentCategory}();
             $generator->version($instance['version']);
             if (!is_null($module)) {
                 $generator->module($module);
             }
             if (isset($instance['variant'])) {
                 $key .= '-' . $instance['variant'];
                 $generator->variant($instance['variant']);
             }
             if (isset($instance['moduleVersion'])) {
                 $key .= '-' . str_replace('.', '', $instance['moduleVersion']);
                 $generator->moduleVersion($instance['moduleVersion']);
             }
             $allDoctypes[$key] = $generator->generate();
         }
     }
     return $allDoctypes;
 }
Example #15
0
 /**
  * @expectedException RuntimeException
  */
 public function testGenerateFunctionMustBeOverwritten()
 {
     $generator = new Generator();
     $generator->generate(new Invoice());
 }
<?php

require_once realpath(dirname(__FILE__) . "/library.php");
Core::init("generation");
$gen = new Generator($_POST);
$response = $gen->generate();
if ($gen->getExportTarget() == "promptDownload") {
    header("Cache-Control: private, no-cache, must-revalidate");
    header("Content-Type: {$response["contentTypeHeader"]}");
}
if (isset($response["promptDownloadFilename"]) && !empty($response["promptDownloadFilename"])) {
    header("Content-Disposition: attachment; filename={$response["promptDownloadFilename"]}");
}
echo $response["content"];