本文整理汇总了PHP中arr::callback_string方法的典型用法代码示例。如果您正苦于以下问题:PHP arr::callback_string方法的具体用法?PHP arr::callback_string怎么用?PHP arr::callback_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arr
的用法示例。
在下文中一共展示了arr::callback_string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form
/**
* Creates and returns a form view object based on the defined inputs,
* rules, and callbacks. ORM::validate is used as the validation method.
*
* Error i18n files follow the format: form_model_name, eg: Model_User would
* use form_user for errors.
*
* @param array values array to validate
* @param boolean YES to save the model, or a URI to redirect, on success
* @return View
*/
public function form(array &$array, $save = NO)
{
$array = Validation::factory($array)->pre_filter('trim');
foreach ($this->rules as $column => $rules) {
foreach ($rules as $rule) {
$array->add_rules($column, $rule);
}
}
foreach ($this->callbacks as $column => $rules) {
foreach ($rules as $rule) {
$array->add_callbacks($column, $rule);
}
}
// Load the form
$form = View::factory($this->view)->set('action', Router::$current_uri)->set('cancel', Router::$current_uri)->set('attributes', array())->bind('inputs', $inputs)->bind('errors', $errors);
if (!$this->validate($array, $save)) {
// Load errors
$errors = $array->errors('form_' . $this->object_name);
}
$inputs = array();
foreach ($this->inputs as $name => $data) {
if (is_int($name)) {
$name = $data;
$data = nil;
} else {
if (isset($data['type']) and $data['type'] === 'dropdown') {
if (isset($data['options']) and !is_array($data['options'])) {
list($model, $attr) = arr::callback_string($data['options']);
// Generate a list of options
$data['options'] = ORM::factory($model)->select_list($attr[0], $attr[1]);
}
if (!isset($data['selected'])) {
$data['selected'] = $array[$name];
}
} elseif (isset($data['type']) and $data['type'] === 'upload') {
// Form must be multi-part
$attributes['enctype'] = 'multipart/form-data';
} else {
$data['value'] = $array[$name];
}
}
if (!isset($data['name'])) {
// Set input name
$data['name'] = $name;
}
if (!isset($data['title'])) {
// Set field title
$data['title'] = ucfirst($name);
}
// Add the column to the inputs
$inputs[arr::remove('title', $data)] = $data;
}
return $form;
}
示例2: connect
/**
* Creates a SwiftMailer instance.
*
* @param string DSN connection string
* @return object Swift object
*/
public static function connect($config = NULL)
{
if (!class_exists('Swift', FALSE)) {
// Load SwiftMailer
require_once Kohana::find_file('vendor', 'swiftmailer/swift_required');
}
// Load default configuration
$config === NULL and $config = Kohana::config('email');
switch ($config['driver']) {
case 'smtp':
// Set port
$port = empty($config['options']['port']) ? NULL : (int) $config['options']['port'];
// Create a SMTP connection
$connection = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port);
if (!empty($config['options']['encryption'])) {
// Set encryption
switch (strtolower($config['options']['encryption'])) {
case 'tls':
case 'ssl':
$connection->setEncryption($config['options']['encryption']);
break;
}
}
// Do authentication, if part of the DSN
empty($config['options']['username']) or $connection->setUsername($config['options']['username']);
empty($config['options']['password']) or $connection->setPassword($config['options']['password']);
if (!empty($config['options']['auth'])) {
// Get the class name and params
list($class, $params) = arr::callback_string($config['options']['auth']);
if ($class === 'PopB4Smtp') {
// Load the PopB4Smtp class manually, due to its odd filename
require Kohana::find_file('vendor', 'swift/Swift/Authenticator/$PopB4Smtp$');
}
// Prepare the class name for auto-loading
$class = 'Swift_Authenticator_' . $class;
// Attach the authenticator
$connection->attachAuthenticator($params === NULL ? new $class() : new $class($params[0]));
}
// Set the timeout to 5 seconds
$connection->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
break;
case 'sendmail':
// Create a sendmail connection
$connection = Swift_SendmailTransport::newInstance($config['options']);
break;
default:
// Use the native connection
$connection = Swift_MailTransport::newInstance();
break;
}
// Create the SwiftMailer instance
return email::$mail = Swift_Mailer::newInstance($connection);
}
示例3: connect
/**
* Creates a SwiftMailer instance.
*
* @param string DSN connection string
* @return object Swift object
*/
public static function connect($config = NULL)
{
if (!class_exists('Swift', FALSE)) {
// Load SwiftMailer
require Kohana::find_file('vendor', 'swift/Swift');
// Register the Swift ClassLoader as an autoload
spl_autoload_register(array('Swift_ClassLoader', 'load'));
}
// Load default configuration
$config === NULL and $config = Kohana::config('email');
switch ($config['driver']) {
case 'smtp':
// Set port
$port = empty($config['options']['port']) ? NULL : (int) $config['options']['port'];
if (empty($config['options']['encryption'])) {
// No encryption
$encryption = Swift_Connection_SMTP::ENC_OFF;
} else {
// Set encryption
switch (strtolower($config['options']['encryption'])) {
case 'tls':
$encryption = Swift_Connection_SMTP::ENC_TLS;
break;
case 'ssl':
$encryption = Swift_Connection_SMTP::ENC_SSL;
break;
}
}
// Create a SMTP connection
$connection = new Swift_Connection_SMTP($config['options']['hostname'], $port, $encryption);
// Do authentication, if part of the DSN
empty($config['options']['username']) or $connection->setUsername($config['options']['username']);
empty($config['options']['password']) or $connection->setPassword($config['options']['password']);
if (!empty($config['options']['auth'])) {
// Get the class name and params
list($class, $params) = arr::callback_string($config['options']['auth']);
if ($class === 'PopB4Smtp') {
// Load the PopB4Smtp class manually, due to its odd filename
require Kohana::find_file('vendor', 'swift/Swift/Authenticator/$PopB4Smtp$');
}
// Prepare the class name for auto-loading
$class = 'Swift_Authenticator_' . $class;
// Attach the authenticator
$connection->attachAuthenticator($params === NULL ? new $class() : new $class($params[0]));
}
// Set the timeout to 5 seconds
$connection->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
break;
case 'sendmail':
// Create a sendmail connection
$connection = new Swift_Connection_Sendmail(empty($config['options']) ? Swift_Connection_Sendmail::AUTO_DETECT : $config['options']);
// Set the timeout to 5 seconds
$connection->setTimeout(5);
break;
default:
// Use the native connection
$connection = new Swift_Connection_NativeMail($config['options']);
break;
}
// Create the SwiftMailer instance
return email::$mail = new Swift($connection);
}
示例4: callback_string
/**
* Tests the arr::callback_string() function.
* @dataProvider callback_string_provider
* @group core.helpers.arr.callback_string
* @test
*/
public function callback_string($input_str, $expected_result)
{
$result = arr::callback_string($input_str);
$this->assertEquals($expected_result, $result);
}