本文整理汇总了PHP中kohana类的典型用法代码示例。如果您正苦于以下问题:PHP kohana类的具体用法?PHP kohana怎么用?PHP kohana使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了kohana类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAudioInfo
public static function getAudioInfo($path)
{
if (!is_file($path)) {
kohana::log('debug', 'Asked for audio info on non-existant file: "' . $path . '"');
return FALSE;
}
$id3 = new getID3();
$info = $id3->analyze($path);
if (!empty($info['error'])) {
kohana::log('debug', 'Unable to analyze "' . $path . '" because ' . implode(' - ', $info['error']));
return FALSE;
}
switch ($info['audio']['dataformat']) {
case 'wav':
return array('type' => $info['audio']['dataformat'], 'compression' => number_format($info['audio']['compression_ratio'], 4), 'channels' => $info['audio']['channels'], 'rates' => $info['audio']['streams'][0]['sample_rate'], 'byterate' => $info['audio']['bitrate'], 'bits' => $info['audio']['bits_per_sample'], 'size' => $info['filesize'], 'length' => number_format($info['playtime_seconds'], 4));
case 'mp1':
return array('type' => $info['audio']['dataformat'], 'compression' => number_format($info['audio']['compression_ratio'], 4), 'channels' => $info['audio']['channels'], 'rates' => $info['audio']['streams'][0]['sample_rate'], 'byterate' => $info['audio']['bitrate'], 'bits' => $info['audio']['bits_per_sample'], 'size' => $info['filesize'], 'length' => number_format($info['playtime_seconds'], 4));
case 'mp3':
return array('type' => $info['audio']['dataformat'], 'compression' => number_format($info['audio']['compression_ratio'], 4), 'channels' => $info['audio']['channels'], 'rates' => $info['audio']['sample_rate'], 'byterate' => $info['audio']['bitrate'], 'bits' => NULL, 'size' => $info['filesize'], 'length' => number_format($info['playtime_seconds'], 4));
case 'ogg':
return array('type' => $info['audio']['dataformat'], 'compression' => number_format($info['audio']['compression_ratio'], 4), 'channels' => $info['audio']['channels'], 'rates' => $info['audio']['sample_rate'], 'byterate' => $info['audio']['bitrate'], 'bits' => NULL, 'size' => $info['filesize'], 'length' => number_format($info['playtime_seconds'], 4));
default:
kohana::log('error', 'Unhandled media type(' . $info['audio']['dataformat'] . ') for file ' . $path);
}
return FALSE;
}
示例2: prepare_connection
/**
* Hook to prepare the database connection. Performs 2 tasks.
* 1) Initialises the search path, unless configured not to do this (e.g. if this is set at db level).
* 2) If this is a report request, sets the connection to read only.
*/
public static function prepare_connection()
{
$uri = URI::instance();
// we havent to proceed futher if a setup call was made
if ($uri->segment(1) == 'setup_check') {
return;
}
// continue to init the system
//
// add schema to the search path
//
$_schema = Kohana::config('database.default.schema');
$query = '';
if (!empty($_schema) && kohana::config('indicia.apply_schema') !== false) {
$query = "SET search_path TO {$_schema}, public, pg_catalog;\n";
}
// Force a read only connection for reporting.
if ($uri->segment(1) == 'services' && $uri->segment(2) == 'report') {
$query .= "SET default_transaction_read_only TO true;\n";
}
if (!empty($query)) {
$db = Database::instance();
$db->query($query);
}
}
示例3: register
public static function register($driver, $hook)
{
$driverName = Telephony::getDriverName();
if (!$driverName or $driverName == 'none') {
return true;
} elseif (!class_exists($driverName)) {
Kohana::log('error', 'Telephony -> Unable to register the dialplan driver \'' . $driverName . '\'');
return false;
}
$hookClass = $driverName . '_' . $driver . '_Driver';
if (!class_exists($hookClass)) {
Kohana::log('error', 'Telephony -> Unable to register the dialplan hook \'' . $driver . '\'(' . $hookClass . ')');
return false;
}
if (empty(self::$dialplanSections)) {
kohana::log('debug', 'Telephony -> EVAL ' . $driverName . '::getDialplanSections();');
$sections = eval('return ' . $driverName . '::getDialplanSections();');
if (is_array($sections)) {
self::$dialplanSections = $sections;
}
}
if (!in_array($hook, self::$dialplanSections)) {
//Logger::ExceptionByCaller();
throw new Exception('The hook ' . $hook . ' is not a recognized telephony global hook. (While trying to register callback ' . $driver . ')');
}
// Register event as _telephony.action with the callback array as the callback
Event::add('_telephony.' . $hook, array($hookClass, $hook));
Kohana::log('debug', 'Telephony -> Added hook for _telephony.' . $hook . ' to call ' . $hookClass . '::' . $hook);
return TRUE;
}
示例4: log_error
/**
* Standardise the dumping of an exception message into the kohana log. E.g.
* try {
* ... code that throws exception ...
* } catch (Exception $e) {
* error::log_error('Error occurred whilst running some code', $e);
* }
*
* @param string $msg A description of where the error occurred.
* $param object $e The exception object.
*/
public static function log_error($msg, $e)
{
kohana::log('error', '#' . $e->getCode() . ': ' . $msg . '. ' . $e->getMessage() . ' at line ' . $e->getLine() . ' in file ' . $e->getFile());
// Double check the log threshold to avoid unnecessary work.
if (kohana::config('config.log_threshold') == 4) {
$trace = $e->getTrace();
$output = "Stack trace:\n";
for ($i = 0; $i < count($trace); $i++) {
if (array_key_exists('file', $trace[$i])) {
$file = $trace[$i]['file'];
} else {
$file = 'Unknown file';
}
if (array_key_exists('line', $trace[$i])) {
$line = $trace[$i]['line'];
} else {
$line = 'Unknown';
}
if (array_key_exists('function', $trace[$i])) {
$function = $trace[$i]['function'];
} else {
$function = 'Unknown function';
}
$output .= "\t" . $file . ' - line ' . $line . ' - ' . $function . "\n";
}
kohana::log('debug', $output);
}
}
示例5: echo_test
public static function echo_test()
{
$featureCode = new FeatureCode();
$featureCode['name'] = 'Echo Test';
$featureCode['registry'] = array('feature' => 'echo');
$featureCode->save();
try {
$location = Doctrine::getTable('Location')->findAll();
if (!$location->count()) {
throw Exception('Could not find location id');
}
$location_id = arr::get($location, 0, 'location_id');
$number = new Number();
$number['user_id'] = users::getAttr('user_id');
$number['number'] = '9999';
$number['location_id'] = $location_id;
$number['registry'] = array('ignoreFWD' => '0', 'ringtype' => 'ringing', 'timeout' => 20);
$dialplan = array('terminate' => array('transfer' => 0, 'voicemail' => 0, 'action' => 'hangup'));
$number['dialplan'] = $dialplan;
$number['class_type'] = 'FeatureCodeNumber';
$number['foreign_id'] = $featureCode['feature_code_id'];
$context = Doctrine::getTable('Context')->findOneByName('Outbound Routes');
$number['NumberContext']->fromArray(array(0 => array('context_id' => $context['context_id'])));
$numberType = Doctrine::getTable('NumberType')->findOneByClass('FeatureCodeNumber');
if (empty($numberType['number_type_id'])) {
return FALSE;
}
$number['NumberPool']->fromArray(array(0 => array('number_type_id' => $numberType['number_type_id'])));
$number->save();
return $number['number_id'];
} catch (Exception $e) {
kohana::log('error', 'Unable to initialize device number: ' . $e->getMessage());
throw $e;
}
}
示例6: __construct
public function __construct()
{
// Hook into routing, but not if running unit tests
if (!in_array(MODPATH . 'phpUnit', kohana::config('config.modules'))) {
Event::add('system.routing', array($this, 'check'));
}
}
示例7: rename
public function rename($id)
{
access::verify_csrf();
$tag = ORM::factory("tag", $id);
if (!$tag->loaded) {
kohana::show_404();
}
$form = tag::get_rename_form($tag);
$valid = $form->validate();
if ($valid) {
$new_name = $form->rename_tag->inputs["name"]->value;
$new_tag = ORM::factory("tag")->where("name", $new_name)->find();
if ($new_tag->loaded) {
$form->rename_tag->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
}
if ($valid) {
$old_name = $tag->name;
$tag->name = $new_name;
$tag->save();
$message = t("Renamed tag %old_name to %new_name", array("old_name" => $old_name, "new_name" => $tag->name));
message::success($message);
log::success("tags", $message);
print json_encode(array("result" => "success", "location" => url::site("admin/tags"), "tag_id" => $tag->id, "new_tagname" => html::clean($tag->name)));
} else {
print json_encode(array("result" => "error", "form" => $form->__toString()));
}
}
示例8: testDateOutOfRange
/**
* Test that a basic date out of range test works.
*/
public function testDateOutOfRange()
{
// Need a test rule we can use to check it works
$ruleArr = array('verification_rule:title' => 'test', 'verification_rule:test_type' => 'PeriodWithinYear', 'verification_rule:error_message' => 'test error', 'metaFields:metadata' => "Tvk=TESTKEY\nStartDate=0801\nEndDate=0831", 'metaFields:data' => "");
$rule = ORM::Factory('verification_rule');
$rule->set_submission_data($ruleArr, false);
if (!$rule->submit()) {
echo kohana::debug($rule->getAllErrors());
throw new exception('Failed to create test rule');
}
try {
$response = data_entry_helper::http_post($this->request, array('sample' => json_encode(array('sample:survey_id' => 1, 'sample:date' => '12/09/2012', 'sample:entered_sref' => 'SU1234', 'sample:entered_sref_system' => 'osgb')), 'occurrences' => json_encode(array(array('occurrence:taxa_taxon_list_id' => $this->ttl->id))), 'rule_types' => json_encode(array('PeriodWithinYear'))));
$errors = json_decode($response['output'], true);
$this->assertTrue(is_array($errors), 'Errors list not returned');
$this->assertTrue(isset($errors[0]['taxa_taxon_list_id']) && $errors[0]['taxa_taxon_list_id'] === $this->ttl->id, 'Incorrect taxa_taxon_list_id returned');
$this->assertTrue(isset($errors[0]['message']) && $errors[0]['message'] === 'test error', 'Incorrect message returned');
foreach ($rule->verification_rule_metadata as $m) {
$m->delete();
}
$rule->delete();
} catch (Exception $e) {
foreach ($rule->verification_rule_metadata as $m) {
$m->delete();
}
$rule->delete();
}
}
示例9: createExtension
public static function createExtension()
{
Event::$data += array('voicemail_password' => self::generatePin(), 'voicemail_timezone' => kohana::config('locale.timezone'), 'voicemail_email_all_messages' => empty(Event::$data['user']['email_address']) ? 0 : 1, 'voicemail_delete_file' => 0, 'voicemail_attach_audio_file' => 1, 'voicemail_email_address' => empty(Event::$data['user']['email_address']) ? '' : Event::$data['user']['email_address']);
extract(Event::$data);
Doctrine::getTable('Voicemail')->getRecordListener()->get('MultiTenant')->setOption('disabled', TRUE);
$name_append = '';
if (!empty($owner_name)) {
$name_append = ' for ' . $owner_name;
}
try {
$voicemail = new Voicemail();
$voicemail['name'] = 'VM ' . $extension . $name_append;
$voicemail['mailbox'] = $extension;
$voicemail['password'] = $voicemail_password;
$voicemail['account_id'] = $account_id;
$voicemail['plugins'] = array('timezone' => array('timezone' => $voicemail_timezone));
$voicemail['registry'] = array('email_all_messages' => $voicemail_email_all_messages, 'delete_file' => $voicemail_delete_file, 'attach_audio_file' => $voicemail_attach_audio_file, 'email_address' => $voicemail_email_address);
$voicemail->save();
$plugin = array('voicemail' => array('mwi_box' => $voicemail['voicemail_id']));
$device['plugins'] = arr::merge($device['plugins'], $plugin);
} catch (Exception $e) {
Doctrine::getTable('Voicemail')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
kohana::log('error', 'Unable to generate voicemail for device: ' . $e->getMessage());
throw $e;
}
Doctrine::getTable('Voicemail')->getRecordListener()->get('MultiTenant')->setOption('disabled', FALSE);
}
示例10: rename
public function rename($id)
{
access::verify_csrf();
$tag = ORM::factory("tag", $id);
if (!$tag->loaded) {
kohana::show_404();
}
// Don't use a form as the form is dynamically created in the js
$post = new Validation($_POST);
$post->add_rules("name", "required", "length[1,64]");
$valid = $post->validate();
if ($valid) {
$new_name = $this->input->post("name");
$new_tag = ORM::factory("tag")->where("name", $new_name)->find();
if ($new_tag->loaded) {
$error_msg = t("There is already a tag with that name");
$valid = false;
}
} else {
$error_msg = $post->errors();
$error_msg = $error_msg[0];
}
if ($valid) {
$old_name = $tag->name;
$tag->name = $new_name;
$tag->save();
$message = t("Renamed tag %old_name to %new_name", array("old_name" => $old_name, "new_name" => $tag->name));
message::success($message);
log::success("tags", $message);
print json_encode(array("result" => "success", "location" => url::site("admin/tags"), "tag_id" => $tag->id, "new_tagname" => html::clean($tag->name)));
} else {
print json_encode(array("result" => "error", "message" => (string) $error_msg));
}
}
示例11: __construct
/**
* 构造方法
*/
public function __construct($img_dir_name = '')
{
$upload_path = kohana::config('upload.directory');
$this->img_dir_name = $img_dir_name ? $img_dir_name : $this->img_dir_name;
$this->dir_name = $upload_path . '/' . $this->img_dir_name . '/';
$this->no_img_file = $upload_path . '/no_img.gif';
}
示例12: getDispositionForm
public function getDispositionForm()
{
$faxprof = Input::instance()->post('faxprofile');
$faxdisp = Doctrine::getTable('FaxDisposition')->find($faxprof['fxp_fxd_id']);
if ($faxdisp) {
$packageobj = Doctrine::getTable('package')->find($faxdisp['fxd_package_id']);
if ($packageobj) {
try {
if (!($package = Package_Catalog::getInstalledPackage($packageobj->name))) {
echo 'Package not ' . $packageobj->name . ' found.';
exit;
}
$formfile = $package['directory'] . '/views/' . $packageobj->name . '/' . $faxdisp['fxd_name'] . '.php';
kohana::Log('debug', 'Looking for view ' . $formfile);
if (file_exists($formfile)) {
$featureFormView = new View($packageobj->name . '/' . $faxdisp['fxd_name']);
kohana::Log('debug', 'View file found.');
if (isset($faxprof['fxp_id']) && !empty($faxprof['fxp_id']) && $faxprof['fxp_id'] != '') {
$faxprofobj = Doctrine::getTable('FaxProfile')->find($faxprof['fxp_id']);
} else {
$faxprofobj = new FaxProfile();
}
$featureFormView->set_global('faxprofile', $faxprofobj);
echo $featureFormView->render(TRUE);
} else {
kohana::Log('debug', 'View file not found.');
}
} catch (Package_Catalog_Exception $e) {
echo 'Package not ' . $packageobj->name . ' found.';
}
}
}
exit;
}
示例13: notify_admins
public function notify_admins($subject = NULL, $message = NULL)
{
// Don't show the exceptions for this operation to the user. Log them
// instead
try {
if ($subject && $message) {
$settings = kohana::config('settings');
$from = array();
$from[] = $settings['site_email'];
$from[] = $settings['site_name'];
$users = ORM::factory('user')->where('notify', 1)->find_all();
foreach ($users as $user) {
if ($user->has(ORM::factory('role', 'admin'))) {
$address = $user->email;
$message .= "\n\n\n\n~~~~~~~~~~~~\n" . Kohana::lang('notifications.admin_footer') . "\n" . url::base() . "\n\n" . Kohana::lang('notifications.admin_login_url') . "\n" . url::base() . "admin";
if (!email::send($address, $from, $subject, $message, FALSE)) {
Kohana::log('error', "email to {$address} could not be sent");
}
}
}
} else {
Kohana::log('error', "email to {$address} could not be sent\n\t\t\t\t - Missing Subject or Message");
}
} catch (Exception $e) {
Kohana::log('error', "An exception occured " . $e->__toString());
}
}
示例14: _send_email_alert
/**
* Sends an email alert
*/
public static function _send_email_alert($post)
{
// Email Alerts, Confirmation Code
$alert_email = $post->alert_email;
$alert_lon = $post->alert_lon;
$alert_lat = $post->alert_lat;
$alert_radius = $post->alert_radius;
$alert_code = text::random('alnum', 20);
$settings = kohana::config('settings');
$to = $alert_email;
$from = array();
$from[] = $settings['alerts_email'] ? $settings['alerts_email'] : $settings['site_email'];
$from[] = $settings['site_name'];
$subject = $settings['site_name'] . " " . Kohana::lang('alerts.verification_email_subject');
$message = Kohana::lang('alerts.confirm_request') . url::site() . 'alerts/verify?c=' . $alert_code . "&e=" . $alert_email;
if (email::send($to, $from, $subject, $message, TRUE) == 1) {
$alert = ORM::factory('alert');
$alert->alert_type = self::EMAIL_ALERT;
$alert->alert_recipient = $alert_email;
$alert->alert_code = $alert_code;
$alert->alert_lon = $alert_lon;
$alert->alert_lat = $alert_lat;
$alert->alert_radius = $alert_radius;
if (isset($_SESSION['auth_user'])) {
$alert->user_id = $_SESSION['auth_user']->id;
}
$alert->save();
self::_add_categories($alert, $post);
return TRUE;
}
return FALSE;
}
示例15: importConfigRoutes
public static function importConfigRoutes()
{
$outboundPatterns = kohana::config('simpleroute.outbound_patterns');
if (!is_array($outboundPatterns)) {
return;
}
// This is the second work arround for the double loading issue... hmmm
$createdPatterns = array();
$simpleRoutes = array();
foreach ($outboundPatterns as $outboundPattern) {
if (empty($outboundPattern['name'])) {
continue;
}
if (in_array($outboundPattern['name'], $createdPatterns)) {
continue;
}
$createdPatterns[] = $outboundPattern['name'];
if (empty($outboundPattern['patterns'])) {
continue;
}
if (!is_array($outboundPattern['patterns'])) {
$outboundPattern['patterns'] = array($outboundPattern['patterns']);
}
$simpleRoute =& $simpleRoutes[];
$simpleRoute['name'] = $outboundPattern['name'];
$simpleRoute['patterns'] = $outboundPattern['patterns'];
}
return $simpleRoutes;
}