2015-07-30 16:37:42 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
2021-04-13 18:04:19 +02:00
|
|
|
* https://ldapsaisie.org
|
2015-07-30 16:37:42 +02:00
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2021-02-05 11:42:55 +01:00
|
|
|
LSsession :: loadLSclass('LSlog_staticLoggerClass');
|
|
|
|
|
2015-07-30 16:37:42 +02:00
|
|
|
/**
|
|
|
|
* Driver to manage ioFormat file of LSldapObject import/export
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
2021-02-05 11:42:55 +01:00
|
|
|
class LSioFormatDriver extends LSlog_staticLoggerClass {
|
2015-07-30 16:37:42 +02:00
|
|
|
|
2022-12-31 21:15:19 +01:00
|
|
|
/**
|
|
|
|
* Driver options
|
|
|
|
* (LSobjects.<type>.ioFormat.<name>.driver_options)
|
|
|
|
* @see LSioFormat::__construct()
|
|
|
|
* @see LSioFormatDriver::__construct()
|
|
|
|
* @see LSioFormatDriver::getOption()
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
protected $options = array();
|
2015-07-30 16:37:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array $options Driver's options
|
2015-07-30 16:37:42 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2015-07-30 16:37:42 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __construct($options) {
|
2015-07-30 16:37:42 +02:00
|
|
|
$this -> options = $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load file
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $path The file path to load
|
2015-07-30 16:37:42 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True if file is loaded, false otherwise
|
2015-07-30 16:37:42 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function loadFile($path) {
|
2015-07-30 16:37:42 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if loaded file data are valid
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True if loaded file data are valid, false otherwise
|
2015-07-30 16:37:42 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isValid() {
|
2015-07-30 16:37:42 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-25 18:02:37 +02:00
|
|
|
* Retrieve all object data contained by the loaded file
|
2015-07-30 16:37:42 +02:00
|
|
|
*
|
|
|
|
* The objects are returned in array :
|
|
|
|
*
|
|
|
|
* array (
|
|
|
|
* array ( // Object 1
|
|
|
|
* '[field1]' => '[value1]',
|
|
|
|
* '[field2]' => '[value2]',
|
|
|
|
* [...]
|
|
|
|
* ),
|
|
|
|
* array ( // Object 2
|
|
|
|
* '[field1]' => '[value1]',
|
|
|
|
* '[field2]' => '[value2]',
|
|
|
|
* [...]
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array The objects contained by the loaded file
|
2015-07-30 16:37:42 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getAll() {
|
2015-07-30 16:37:42 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-25 18:02:37 +02:00
|
|
|
* Retrieve fields names of the loaded file
|
2015-07-30 16:37:42 +02:00
|
|
|
*
|
|
|
|
* The fields names are returned in array :
|
|
|
|
*
|
|
|
|
* array (
|
|
|
|
* '[field1]',
|
|
|
|
* '[field2]',
|
|
|
|
* [...]
|
|
|
|
* )
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array The fields names of the loaded file
|
2015-07-30 16:37:42 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getFieldNames() {
|
2015-07-30 16:37:42 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-25 18:02:37 +02:00
|
|
|
* Retrieve all objects data of the loaded file formated
|
2015-07-30 16:37:42 +02:00
|
|
|
*
|
|
|
|
* This method format objects data using ioFormat configuration
|
|
|
|
* given as parameters.
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array $fields of file's fields name mapping with object attribute
|
|
|
|
* @param array $generated_fields of object attribute to generate using other object data
|
2015-07-30 16:37:42 +02:00
|
|
|
*
|
2023-01-02 01:17:46 +01:00
|
|
|
* @return array|false All objects data of the loaded file formated, or false
|
2015-07-30 16:37:42 +02:00
|
|
|
**/
|
2020-11-30 19:44:14 +01:00
|
|
|
public function getAllFormated($fields, $generated_fields) {
|
2015-07-30 16:37:42 +02:00
|
|
|
if (!is_array($fields)) return False;
|
|
|
|
if (!is_array($generated_fields)) $generated_fields=array();
|
2020-11-30 19:44:14 +01:00
|
|
|
$all = $this -> getAll();
|
2015-07-30 16:37:42 +02:00
|
|
|
if (!is_array($all)) return False;
|
2020-11-30 19:44:14 +01:00
|
|
|
$retall = array();
|
2023-07-03 12:34:14 +02:00
|
|
|
foreach($all as $idx => $one) {
|
2020-11-30 19:44:14 +01:00
|
|
|
$retone = array();
|
2015-07-30 16:37:42 +02:00
|
|
|
foreach($fields as $key => $attr) {
|
|
|
|
if (!isset($one[$key])) continue;
|
2020-11-30 19:44:14 +01:00
|
|
|
if (!isset($retone[$attr])) $retone[$attr] = array();
|
|
|
|
$retone[$attr][] = $one[$key];
|
2015-07-30 16:37:42 +02:00
|
|
|
}
|
2021-04-27 12:13:32 +02:00
|
|
|
foreach ($generated_fields as $attr => $formats) {
|
|
|
|
$retone[$attr] = array();
|
2023-05-12 11:50:11 +02:00
|
|
|
if (is_callable($formats)) {
|
2023-07-03 12:34:14 +02:00
|
|
|
$retone[$attr] = call_user_func_array($formats, array($retone, $one));
|
|
|
|
if ($retone[$attr] === false) {
|
|
|
|
LSerror :: addErrorCode(
|
|
|
|
'LSioFormatDriver_01',
|
|
|
|
array('attr' => $attr, 'object' => (is_int($idx)?"#$idx":"'$idx'"))
|
|
|
|
);
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
$retone[$attr] = ensureIsArray($retone[$attr]);
|
2023-05-12 11:50:11 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach (ensureIsArray($formats) as $format) {
|
|
|
|
$value = getFData($format, $retone);
|
|
|
|
if (!is_empty($value)) {
|
|
|
|
$retone[$attr][] = $value;
|
|
|
|
}
|
2021-04-27 12:13:32 +02:00
|
|
|
}
|
2015-07-30 16:37:42 +02:00
|
|
|
}
|
2021-04-27 12:13:32 +02:00
|
|
|
if (empty($retone[$attr]))
|
|
|
|
unset($retone[$attr]);
|
2015-07-30 16:37:42 +02:00
|
|
|
}
|
2020-11-30 19:44:14 +01:00
|
|
|
$retall[] = $retone;
|
2015-07-30 16:37:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $retall;
|
|
|
|
}
|
|
|
|
|
2021-02-05 11:42:55 +01:00
|
|
|
/**
|
|
|
|
* Export objects data
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array $objects_data of objects data to export
|
|
|
|
* @param resource|null $stream The output stream (optional, default: STDOUT)
|
2021-02-05 11:42:55 +01:00
|
|
|
*
|
2021-08-25 18:02:37 +02:00
|
|
|
* @return boolean True on success, False otherwise
|
2021-02-05 11:42:55 +01:00
|
|
|
*/
|
2021-02-05 18:12:44 +01:00
|
|
|
public function exportObjectsData($objects_data, $stream=null) {
|
2021-02-05 11:42:55 +01:00
|
|
|
// Must be implement in real drivers
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a option parameter (or default value)
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $param The configuration parameter
|
|
|
|
* @param mixed $default The default value (default : null)
|
|
|
|
* @param string $cast Cast resulting value in specific type (default : disabled)
|
2021-02-05 11:42:55 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed The option parameter value or default value if not set
|
2021-02-05 11:42:55 +01:00
|
|
|
**/
|
|
|
|
public function getOption($param, $default=null, $cast=null) {
|
|
|
|
return LSconfig :: get($param, $default, $cast, $this -> options);
|
|
|
|
}
|
|
|
|
|
2015-07-30 16:37:42 +02:00
|
|
|
}
|
2023-07-03 12:34:14 +02:00
|
|
|
|
|
|
|
LSerror :: defineError('LSioFormatDriver_01',
|
|
|
|
___("LSioFormatDriver : Fail to generate the value of the attribute %{attr} of the object %{object}.")
|
|
|
|
);
|