本文整理汇总了PHP中tools::unserialize方法的典型用法代码示例。如果您正苦于以下问题:PHP tools::unserialize方法的具体用法?PHP tools::unserialize怎么用?PHP tools::unserialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tools
的用法示例。
在下文中一共展示了tools::unserialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEntity
/**
* Get an entity
* @param string $entity
* @return entity|false
*/
public function getEntity($entity)
{
if (isset($this->model[$entity])) {
return $this->model[$entity];
} else {
if (is_file('modules/' . $this->name . '/model/' . $entity . '.' . \app::$config['dev']['serialization'])) {
if (!class_exists($this->name . '\\model\\' . $entity)) {
include 'modules/' . $this->name . '/model/' . $entity . '.php';
}
$this->model[$entity] = \tools::unserialize('modules/' . $this->name . '/model/' . $entity);
return $this->model[$entity];
} else {
throw new \Exception(t('Entity doesn\'t exist', FALSE) . ' : ' . s($entity));
}
}
}
示例2: saveModelAction
/**
* Save model
* @return string
*/
protected function saveModelAction($module, $list, $oldSchema)
{
$schema = json_decode($list);
$oldSchema = json_decode($oldSchema, TRUE);
$tableExists = array();
/* Get roles ids with behavior anonymous */
$rolesBehaviorAnonymous = array();
foreach (\app::getModule('core')->getEntity('role') as $role) {
if ($role->permissions == 0) {
$rolesBehaviorAnonymous[] = $role->id_role;
}
}
if (is_array($schema)) {
foreach ($schema as $tableKey => $table) {
/* Prepare entity's properties */
$tplProp = '';
$tplParam = '';
$tplAssign = '';
$args = array();
$matchOldNewNames = array();
foreach ($table->properties as $fieldName => $fieldProps) {
list($name, $type) = explode(':', $fieldName);
$tplProp .= "\t" . 'protected $' . $name . ';' . PHP_EOL;
//generates attributes
$tplParam .= '\\' . $type . ' $' . $name . ',';
//generates the constructor parameters
$tplAssign .= "\t\t" . '$this->' . $name . ' = $' . $name . ";\n";
//generates assignments in the constructor
$reflectionObj = new \ReflectionClass($type);
$fieldProps = json_encode($fieldProps);
$fieldProps = json_decode($fieldProps, true);
if (isset($fieldProps['oldName']) && ($fieldProps['oldName'] != $name && !empty($fieldProps['oldName']))) {
$matchOldNewNames[$name] = $fieldProps['oldName'];
}
unset($fieldProps['oldName']);
$field = $reflectionObj->newInstanceArgs(array('name' => $fieldName, 'properties' => $fieldProps));
if (!isset($fieldProps['rights'])) {
/* Set rights forbidden for non admins, admins are allowed by default */
foreach ($rolesBehaviorAnonymous as $id_role) {
$field->setRights($id_role, 0);
}
}
$args[] = $field;
}
/* Prepare entity's php file */
$tpl = '<?php
namespace ' . $module . '\\model;
/**
* Description of entity ' . $table->name . '
* @author Parsimony
* @top ' . $table->top . '
* @left ' . $table->left . '
*/
class ' . $table->name . ' extends \\entity {
' . $tplProp . '
public function __construct(' . substr($tplParam, 0, -1) . ') {
parent::__construct();
' . $tplAssign . '
}
';
$model = 'modules/' . $module . '/model/' . $table->name . '.php';
if (!is_file($model)) {
$tpl .= '// DON\'T TOUCH THE CODE ABOVE ##########################################################' . PHP_EOL . '}' . PHP_EOL . '?>';
} else {
$code = file_get_contents($model);
$tpl = preg_replace('@<\\?php(.*)}(.*)?(ABOVE ##########################################################)?@Usi', $tpl, $code);
}
\tools::file_put_contents($model, $tpl);
include_once $model;
$oldObjModel = FALSE;
if (is_file('modules/' . $module . '/model/' . $table->oldName . '.' . \app::$config['dev']['serialization'])) {
$oldObjModel = \tools::unserialize('modules/' . $module . '/model/' . $table->oldName);
}
// Change table Name if changes
if ($table->name !== $table->oldName) {
\PDOconnection::getDB()->exec('ALTER TABLE ' . PREFIX . $module . '_' . $table->oldName . ' RENAME TO ' . $module . '_' . $table->name . ';');
unlink('modules/' . $module . '/model/' . $table->oldName . '.php');
unlink('modules/' . $module . '/model/' . $table->oldName . '.' . \app::$config['dev']['serialization']);
}
// make a reflection object
$reflectionObj = new \ReflectionClass($module . '\\model\\' . $table->name);
$newObj = $reflectionObj->newInstanceArgs($args);
$newObj->__wakeup();
/* Set entity's properties */
$newObj->setTitle($table->title);
$newObj->behaviorTitle = $table->behaviorTitle;
$newObj->behaviorDescription = $table->behaviorDescription;
$newObj->behaviorKeywords = $table->behaviorKeywords;
$newObj->behaviorImage = $table->behaviorImage;
/* Set entity's rights */
if (is_object($oldObjModel)) {
$newObj->setAllRights($oldObjModel->getAllRights());
} else {
/* Set rights forbidden for non admins, admins are allowed by default */
//.........这里部分代码省略.........
示例3: get
/**
* Serialize and Save this theme object
* @param string $module
* @param string $name
*/
public static function get($module, $name)
{
$file = stream_resolve_include_path($module . '/themes/' . $name . '/theme.' . \app::$config['dev']['serialization']);
if ($file) {
return \tools::unserialize(substr($file, 0, -4));
} else {
$theme = new theme('container', $name, $module);
$theme->save();
return $theme;
}
}