本文整理汇总了PHP中Ak::is_array方法的典型用法代码示例。如果您正苦于以下问题:PHP Ak::is_array方法的具体用法?PHP Ak::is_array怎么用?PHP Ak::is_array使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ak
的用法示例。
在下文中一共展示了Ak::is_array方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLocation
public function getLocation($Location)
{
if (Ak::is_array($Location)) {
return array_values($this->Location->collect($Location, 'id', 'name'));
} else {
return $Location->get('name');
}
}
示例2: collect
/**
* Collect is a function for selecting items from double depth array
* like the ones returned by the AkActiveRecord. This comes useful when you just need some
* fields for generating tables, select lists with only desired fields.
*
* $people_for_select = Ak::select($People->find(),'id','email');
*
* Returns something like:
* array (
* array ('10' => 'jose@example.com'),
* array ('15' => 'alicia@example.com'),
* array ('16' => 'hilario@example.com'),
* array ('18' => 'bermi@example.com')
* );
*/
public function collect($source_array, $key_index, $value_index)
{
$resulting_array = array();
if (!empty($source_array) && Ak::is_array($source_array)) {
foreach ($source_array as $source_item) {
$resulting_array[$source_item->get($key_index)] = $source_item->get($value_index);
}
}
return $resulting_array;
}
示例3: _setAssociations
public function _setAssociations($assoc_name, $val, &$parent, $load_acts = true)
{
static $instances = array();
static $instance_attributes = array();
if ($assoc_name[0] == '_') {
return;
}
if (method_exists($parent, 'getAssociationOption')) {
$class = $parent->getType();
$instance = new $class();
if (isset($instance->{$assoc_name}) && method_exists($instance->{$assoc_name}, 'getAssociationOption')) {
$class = $instance->{$assoc_name}->getAssociationOption('class_name');
if (!isset($instances[$class])) {
$instance = new $class();
$instances[$class] =& $instance;
} else {
$instance =& $instances[$class];
}
} else {
if (isset($parent->{$assoc_name}) && ($parent->{$assoc_name} instanceof AkHasMany || $parent->{$assoc_name} instanceof AkHasAndBelongsToMany)) {
if (!isset($instances[$parent->getType() . '-' . $assoc_name])) {
$instance = $parent->{$assoc_name}->getAssociatedModelInstance();
$instances[$parent->getType() . '-' . $assoc_name] =& $instance;
} else {
$instance =& $instances[$parent->getType() . '-' . $assoc_name];
}
} else {
if (isset($parent->{$assoc_name}) && method_exists($parent->{$assoc_name}, 'getType') && !in_array($parent->{$assoc_name}->getType(), array('belongsTo', 'hasOne', 'hasOne', 'hasMany', 'hasAndBelongsToMany'))) {
$instance = $parent->{$assoc_name};
} else {
if (isset($instance->{$assoc_name})) {
if (!isset($instances[$instance->getType() . '-' . $assoc_name])) {
$instance = $instance->{$assoc_name}->getAssociatedModelInstance();
$instances[$instance->getType() . '-' . $assoc_name] =& $instance;
} else {
$instance =& $instances[$instance->getType() . '-' . $assoc_name];
}
} else {
$this->_ActiveRecord->log('Cannot find association:' . $assoc_name . ' on ' . $parent->getType());
return;
}
}
}
}
} else {
if (!$parent->{$assoc_name}) {
$this->_ActiveRecord->log($parent->getType() . '->' . $assoc_name . ' does not have assoc');
return;
}
if (!isset($instances[$parent->getType() . '-' . $assoc_name])) {
$instance = $parent->{$assoc_name}->getAssociatedModelInstance();
$instances[$parent->getType() . '-' . $assoc_name] =& $instance;
} else {
$instance =& $instances[$parent->getType() . '-' . $assoc_name];
}
}
if (is_numeric(key($val))) {
$owner = $val;
} else {
$owner = array($val);
}
if (!isset($instance_attributes[$instance->getType()])) {
$available_attributes = $instance->getAvailableAttributes();
$available_attributes = array_keys($available_attributes);
$instance_attributes[$instance->getType()] = $available_attributes;
} else {
$available_attributes = $instance_attributes[$instance->getType()];
}
foreach ($owner as $data) {
if (!isset($diff)) {
$diff = @array_diff(@array_keys($data), $available_attributes);
$nondiff = array();
if (Ak::is_array($diff)) {
foreach (array_keys($diff) as $d) {
$nondiff[$d] = null;
}
}
}
$available = @array_merge($data, $nondiff);
if (empty($available[$instance->getPrimaryKey()])) {
$parent->{$assoc_name}->_loaded = true;
continue;
}
$available['load_associations'] = false;
$available['load_acts'] = $load_acts;
$available = $instance->castAttributesFromDatabase($available);
$obj =& $parent->{$assoc_name}->build($available, false);
$obj->_newRecord = false;
$parent->{$assoc_name}->_loaded = true;
$obj->_loaded = true;
if (Ak::is_array($diff)) {
foreach (array_values($diff) as $rel) {
$this->_setAssociations($rel, $data[$rel], $obj);
}
}
}
}
示例4: convert
/**
* The Akelos Framework has an standardized way to convert between formats.
* You can find available converters on AkConverters
*
* Usage Example: In order to convert from HTML to RTF you just need to call.
* $rtf = Ak::convert('html','rtf', $my_html_file, array('font_size'=> 24));
*
* Where the last option is an array of options for selected converter.
*
* Previous example is the same as.
*
* $rtf = Ak::convert(array('from'=>'html','to'=>'rtf', 'source' => $my_html_file, 'font_size'=> 24));
*
* In order to create converters, you just need to name them "SourceFormatName + To + DestinationFormatName".
* Whenever you need to call the, you need to specify the "path" option where your converter is located.
* The only thing you converter must implement is a convert function. Passes options will be made available
* as attributes on the converter.
* If your converter needs to prepare something before the convert method is called, you just need to implement
* a "init" method. You can avoid this by inspecting passed attributes to your constructor
*/
static function convert()
{
$args = func_get_args();
$number_of_arguments = func_num_args();
if ($number_of_arguments > 1) {
$options = array();
if ($number_of_arguments > 3 && Ak::is_array($args[$number_of_arguments - 1])) {
$options = array_pop($args);
}
$options['from'] = $args[0];
$options['to'] = $args[1];
$options['source'] = $args[2];
} else {
$options = $args;
}
if ($options['from'] == $options['to']) {
return $options['source'];
}
$options['class_prefix'] = empty($options['class_prefix']) && empty($options['path']) ? 'Ak' : $options['class_prefix'];
$options['path'] = rtrim(empty($options['path']) ? AK_ACTIVE_SUPPORT_DIR . DS . 'converters' : $options['path'], DS . "\t ");
$converter_file_name = AkInflector::underscore($options['from']) . '_to_' . AkInflector::underscore($options['to']);
$converter_class_name = $options['class_prefix'] . AkInflector::camelize($converter_file_name);
if (!class_exists($converter_class_name)) {
$file_name = $options['path'] . DS . $converter_file_name . '.php';
if (!file_exists($file_name)) {
if (defined('AK_REMOTE_CONVERTER_URI')) {
$result = AkRemoteConverter::convert($options['from'], $options['to'], $options['source']);
if ($result !== false) {
return $result;
}
}
trigger_error(Ak::t('Could not locate %from to %to converter on %file_name', array('%from' => $options['from'], '%to' => $options['to'], '%file_name' => $file_name)), E_USER_NOTICE);
return false;
}
require_once $file_name;
}
if (!class_exists($converter_class_name)) {
trigger_error(Ak::t('Could not load %converter_class_name converter class', array('%converter_class_name' => $converter_class_name)), E_USER_NOTICE);
return false;
}
$converter = new $converter_class_name($options);
foreach ($options as $option => $value) {
$option[0] != '_' ? $converter->{$option} = $value : null;
}
if (method_exists($converter, 'init')) {
$converter->init();
}
return $converter->convert((array) $options);
}