public function testPhpSerialize() { $phpCode = \common_Utils::toPHPVariableString(new FreeAccess()); $restoredModel = eval('return ' . $phpCode . ';'); $this->assertInstanceOf('oat\\generis\\model\\data\\permission\\PermissionInterface', $restoredModel); $this->assertEquals(array(), $restoredModel->getSupportedRights()); $this->assertEquals(array('res1' => array(FreeAccess::RIGHT_UNSUPPORTED)), $restoredModel->getPermissions($this->user, array('res1'))); }
public function __toPhpCode() { return "new " . __CLASS__ . "(" . \common_Utils::toPHPVariableString($this->data) . ',' . \common_Utils::toPHPVariableString(self::SERIAL_VERSION) . ")"; }
public function testSerialisation() { $toSerialize = array('a' => "test \\ ", 'b' => new core_kernel_classes_Resource('doesnotexist'), 'c' => array('1', '2', array(common_user_auth_Service::singleton()))); $value = eval("return " . common_Utils::toPHPVariableString($toSerialize) . ";"); $this->assertEquals($toSerialize, $value); }
protected function copyFile($file, $destination = null, $extra = array()) { $sample = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $file); $destination = $this->getDestinationDirectory() . (is_null($destination) ? $file : $destination); if (!file_exists(dirname($destination))) { mkdir(dirname($destination), 0770, true); } $map = array('{id}' => $this->id, '{name}' => self::escape($this->label), '{version}' => self::escape($this->version), '{author}' => self::escape($this->author), '{license}' => self::escape($this->license), '{description}' => self::escape($this->description), '{authorNs}' => $this->authorNamespace, '{dependencies}' => 'array(\'' . implode('\',\'', array_keys($this->requires)) . '\')', '{requires}' => \common_Utils::toPHPVariableString($this->requires), '{managementRole}' => GENERIS_NS . '#' . $this->id . 'Manager', '{licenseBlock}' => $this->getLicense()); $map = array_merge($map, $extra); $content = str_replace(array_keys($map), array_values($map), $sample); return file_put_contents($destination, $content); }
/** * Compile the $test meta-data into PHP source code for maximum performance. The file is * stored into PRIVATE_DIRECTORY/test-meta.php. * * @param AssessmentTest $test */ protected function compileMeta(AssessmentTest $test) { $compiledDocDir = $this->getPrivateDirectory(); $meta = taoQtiTest_helpers_TestCompilerUtils::testMeta($test); $phpCode = common_Utils::toPHPVariableString($meta); $phpCode = '<?php return ' . $phpCode . '; ?>'; $compiledDocDir->write(TAOQTITEST_COMPILED_META_FILENAME, $phpCode); }
/** * Generate the php code that returns the provided value * * @param string $key * @param mixed $value * @return string */ protected function getContent($key, $value) { return $this->humanReadable ? "<?php return " . common_Utils::toHumanReadablePhpString($value) . ";" . PHP_EOL : "<?php return " . common_Utils::toPHPVariableString($value) . ";"; }
public function exportDiffToPhp() { /* return "<?php return " . common_Utils::toPHPVariableString(array( 'comments' => $this->comments, 'toAdd' => $this->toAdd, 'toRemove' => $this->toRemove )) . ";?>"; */ $string = "<?php return array(\n 'comments' => " . common_Utils::toPHPVariableString($this->comments) . ",\n 'toAdd' => array(" . PHP_EOL; foreach ($this->toAdd as $key => $val) { $string .= common_Utils::toPHPVariableString($key) . ' => ' . common_Utils::toPHPVariableString($val) . ',' . PHP_EOL; } $string .= ")," . PHP_EOL; $string .= "'toRemove' => array(" . PHP_EOL; foreach ($this->toRemove as $key => $val) { $string .= common_Utils::toPHPVariableString($key) . ' => ' . common_Utils::toPHPVariableString($val) . ',' . PHP_EOL; } $string .= "));"; return $string; }
if (file_exists($file) && !is_writable($file)) { echo 'No write access to "' . $file . '", aborting.' . PHP_EOL; exit(1); } if ($taoExtension->hasConfig(tao_models_classes_fsAccess_Manager::CONFIG_KEY)) { $configData = array(); foreach ($taoExtension->getConfig(tao_models_classes_fsAccess_Manager::CONFIG_KEY) as $serialized) { $provider = tao_models_classes_fsAccess_AccessProvider::restoreFromString($serialized); if ($provider instanceof tao_models_classes_fsAccess_TokenAccessProvider) { echo 'Restoring provider with Id ' . $provider->getId() . PHP_EOL; list($class, $id, $fsUri, $rawConfig) = explode(' ', $serialized, 4); $config = json_decode($rawConfig, true); if (!is_array($config)) { echo 'Unable to read config for access provider ' . $provider->getUri() . ', aborting.' . PHP_EOL; exit(1); } } $configData[$provider->getId()] = array('secret' => $config['secret'], 'folder' => $provider->getFileSystem()->getPath()); } $success = file_put_contents($file, "<?php return " . common_Utils::toPHPVariableString($configData) . ";"); if ($success !== false) { echo 'Successfully saved GetFile config.' . PHP_EOL; die(0); } else { echo 'Unable to write to "' . $file . '", aborting.' . PHP_EOL; die(1); } } else { echo 'No access providers found, aborting.' . PHP_EOL; exit(1); }
/** * (non-PHPdoc) * @see \oat\oatbox\PhpSerializable::__toPhpCode() */ public function __toPhpCode() { $params = \common_Utils::toPHPVariableString($this->getOptions(), true); return 'new ' . get_class($this) . '(' . $params . ')'; }