Page MenuHomePhorge

Source.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

Source.php

<?php
namespace Kolab\FreeBusy;
/**
* Abstract class to fetch free/busy data from a specific source
*/
abstract class Source
{
protected $config = array();
/**
* Factory method creating an instace of Source according to config
*
* @param array Hash array with config
*/
public static function factory($url)
{
$config = parse_url($url);
$config['url'] = $url;
switch ($config['scheme']) {
case 'file': return new SourceFile($config);
case 'imap':
case 'imaps': return new SourceIMAP($config);
case 'http':
case 'https': return new SourceURL($config);
}
Logger::get('source')->addError("Invalid source configuration: " . $url);
return null;
}
/**
* Default constructor
*/
public function __construct($config)
{
$this->config = $config;
}
/**
* Retrieve free/busy data for the given user
*
* @param array Hash array with user attributes
*/
abstract public function getFreeBusyData($user, $extended);
/**
* Replace all %varname strings in config with values from $user
*/
protected function getUserConfig($user)
{
$config = array();
foreach ($this->config as $k => $val) {
if (is_string($val) && strpos($val, '%') !== false) {
$val = preg_replace_callback(
'/%\{?([a-z0-9]+)\}?/',
function($m) use ($user) { return $user[$m[1]]; },
$val);
}
$config[$k] = $val;
}
return $config;
}
}

File Metadata

Mime Type
text/x-php
Expires
Wed, Jul 8, 5:25 PM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1051110
Default Alt Text
Source.php (1 KB)

Event Timeline