upgrade
This commit is contained in:
64
main/auth/shibboleth/lib/scaffolder/scaffolder.class.php
Normal file
64
main/auth/shibboleth/lib/scaffolder/scaffolder.class.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
* Scaffolder. Genereate code templates from the database layout.
|
||||
* See /template/ for the code being generated
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
class Scaffolder
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @staticvar boolean $result
|
||||
* @return Scaffolder
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new self();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function scaffold($table_name, $class_name = '', $prefix = '_')
|
||||
{
|
||||
$db_name = Database :: get_main_database();
|
||||
$sql = "SELECT * FROM `$db_name`.`$table_name` LIMIT 1";
|
||||
|
||||
$fields = array();
|
||||
$unique_fields = array();
|
||||
$rs = Database::query($sql, null, __FILE__);
|
||||
while ($field = mysql_fetch_field($rs))
|
||||
{
|
||||
$fields[] = $field;
|
||||
if ($field->primary_key)
|
||||
{
|
||||
/**
|
||||
* Could move that to an array to support multiple keys
|
||||
*/
|
||||
$id_name = $field->name;
|
||||
}
|
||||
if ($field->unique_key | $field->primary_key)
|
||||
{
|
||||
$keys[] = $field->name;
|
||||
}
|
||||
}
|
||||
$name = $table_name;
|
||||
$class_name = ucfirst($table_name);
|
||||
|
||||
|
||||
|
||||
ob_start();
|
||||
include __DIR__.'/template/model.php';
|
||||
$result = ob_get_clean();
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
146
main/auth/shibboleth/lib/scaffolder/template/default.php
Normal file
146
main/auth/shibboleth/lib/scaffolder/template/default.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
|
||||
echo '<?php';
|
||||
?>
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
* This file is autogenerated. Do not modifiy it.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Model for table <?php echo $table_name ?>
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class <?php echo $prefix . $class_name ?>
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* Store for <?php echo $class_name ?> objects. Interact with the database.
|
||||
*
|
||||
* @return <?php echo $class_name ?>Store
|
||||
*/
|
||||
public static function store()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new <?php echo $class_name ?>Store();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public static function create($data = null)
|
||||
{
|
||||
return self::store()->create_object($data);
|
||||
}
|
||||
|
||||
<?php foreach($fields as $field){?>
|
||||
public $<?php echo $field->name; ?> = <?php echo $field->def ? $field->def : 'null'; ?>;
|
||||
<?php }?>
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
return self::store()->save($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for <?php echo $class_name ?> objects. Interact with the database.
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class <?php echo $prefix . $class_name ?>Store extends Store
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>Store
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new self();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('<?php echo $table_name;?>', '<?php echo $class_name;?>', '<?php echo $id_name;?>');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public function get($w)
|
||||
{
|
||||
$args = func_get_args();
|
||||
$f = array('parent', 'get');
|
||||
return call_user_func_array($f, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public function create_object($data)
|
||||
{
|
||||
return parent::create_object($data);
|
||||
}
|
||||
<?php foreach($keys as $key){?>
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public function get_by_<?php echo $key ?>($value)
|
||||
{
|
||||
return $this->get(array('<?php echo $key; ?>' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function <?php echo $key ?>_exists($value)
|
||||
{
|
||||
return $this->exist(array('<?php echo $key; ?>' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_by_<?php echo $key ?>($value)
|
||||
{
|
||||
return $this->delete(array('<?php echo $key; ?>' => $value));
|
||||
}
|
||||
<?php }?>
|
||||
}
|
||||
146
main/auth/shibboleth/lib/scaffolder/template/model.php
Normal file
146
main/auth/shibboleth/lib/scaffolder/template/model.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
|
||||
echo '<?php';
|
||||
?>
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
* This file is autogenerated. Do not modifiy it.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Model for table <?php echo $table_name ?>
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class <?php echo $prefix . $class_name ?>
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* Store for <?php echo $class_name ?> objects. Interact with the database.
|
||||
*
|
||||
* @return <?php echo $class_name ?>Store
|
||||
*/
|
||||
public static function store()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new <?php echo $class_name ?>Store();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public static function create($data = null)
|
||||
{
|
||||
return self::store()->create_object($data);
|
||||
}
|
||||
|
||||
<?php foreach($fields as $field){?>
|
||||
public $<?php echo $field->name; ?> = <?php echo $field->def ? $field->def : 'null'; ?>;
|
||||
<?php }?>
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
return self::store()->save($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for <?php echo $class_name ?> objects. Interact with the database.
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class <?php echo $prefix . $class_name ?>Store extends Store
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>Store
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new self();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('<?php echo $table_name;?>', '<?php echo $class_name;?>', '<?php echo $id_name;?>');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public function get($w)
|
||||
{
|
||||
$args = func_get_args();
|
||||
$f = array('parent', 'get');
|
||||
return call_user_func_array($f, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public function create_object($data)
|
||||
{
|
||||
return parent::create_object($data);
|
||||
}
|
||||
<?php foreach($keys as $key){?>
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <?php echo $class_name ?>
|
||||
*/
|
||||
public function get_by_<?php echo $key ?>($value)
|
||||
{
|
||||
return $this->get(array('<?php echo $key; ?>' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function <?php echo $key ?>_exists($value)
|
||||
{
|
||||
return $this->exist(array('<?php echo $key; ?>' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_by_<?php echo $key ?>($value)
|
||||
{
|
||||
return $this->delete(array('<?php echo $key; ?>' => $value));
|
||||
}
|
||||
<?php }?>
|
||||
}
|
||||
39
main/auth/shibboleth/lib/scaffolder/template/public.php
Normal file
39
main/auth/shibboleth/lib/scaffolder/template/public.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
|
||||
echo '<?php';
|
||||
?>
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
*
|
||||
* Model for table <?php echo $table_name ?>
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class <?php echo $class_name ?>
|
||||
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for <?php echo $class_name ?> objects. Interact with the database.
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class <?php echo $class_name ?>Store extends Store
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user