本文整理汇总了PHP中Ak::convert方法的典型用法代码示例。如果您正苦于以下问题:PHP Ak::convert方法的具体用法?PHP Ak::convert怎么用?PHP Ak::convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ak
的用法示例。
在下文中一共展示了Ak::convert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_should_establish_multiple_connections
function test_should_establish_multiple_connections()
{
if(AK_PHP5){
$db_settings = Ak::convert('yaml', 'array', AK_CONFIG_DIR.DS.'database.yml');
$db_settings['sqlite_databases'] = array(
'database_file' => AK_TMP_DIR.DS.'testing_sqlite_database.sqlite',
'type' => 'sqlite'
);
file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
$this->installAndIncludeModels(array('TestOtherConnection'));
Ak::import('test_other_connection');
$OtherConnection = new TestOtherConnection(array('name'=>'Delia'));
$this->assertTrue($OtherConnection->save());
$this->installAndIncludeModels(array('DummyModel'=>'id,name'));
$Dummy = new DummyModel();
$this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection());
unset($db_settings['sqlite_databases']);
file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
}
}
示例2: _getMenuOptionsForControllersInModule
public function _getMenuOptionsForControllersInModule($type = 'admin')
{
$controllers = AkFileSystem::dir(AK_CONTROLLERS_DIR . DS . $this->_controller->getModuleName(), array('dirs' => false));
sort($controllers);
$menu_options = array();
foreach ($controllers as $controller) {
$controller_name = substr($controller, 0, -15);
$menu_options[AkInflector::titleize($controller_name)] = array('id' => $controller_name, 'url' => array('controller' => $controller_name));
}
$options_file = $this->_getMenuOptionsFile($type);
if (!file_exists($options_file)) {
AkFileSystem::file_put_contents(AK_CONFIG_DIR . DS . $options_file, Ak::convert('array', 'yaml', array('default' => $menu_options)));
}
return $menu_options;
}
示例3: convert
public function convert($options)
{
static $_tags = array();
$header = !isset($options['header']) ? "<?xml version=\"1.0\"?>\r\n" : $options['header'];
$parent = !isset($options['parent']) ? 'EMPTY_TAG' : $options['parent'];
$xml = $header;
foreach ($this->source as $key => $value) {
$key = is_numeric($key) ? $parent : $key;
$value = is_array($value) ? "\r\n" . Ak::convert('array', 'xml', $this->source, array('header' => '', 'parent' => $parent)) : $value;
$_tags[$key] = $key;
$xml .= sprintf("<%s>%s</%s>\r\n", $key, $value, $key);
$parent = $key;
}
foreach ($_tags as $_tag) {
$xml = str_replace(array("<{$_tag}>\r\n<{$_tag}>", "</{$_tag}>\r\n</{$_tag}>"), array("<{$_tag}>", "</{$_tag}>"), $xml);
}
return $xml;
}
示例4: populateTables
function populateTables()
{
$args = func_get_args();
$tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array();
foreach ($tables as $table){
$file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml';
if(!file_exists($file)){
continue;
}
$class_name = AkInflector::modulize($table);
if($this->instantiateModel($class_name)){
$items = Ak::convert('yaml','array',file_get_contents($file));
foreach ($items as $item){
$this->{$class_name}->create($item);
}
}
}
}
示例5: test_should_establish_multiple_connections
public function test_should_establish_multiple_connections()
{
$db_file_existed = false;
if (file_exists(AkConfig::getDir('config') . DS . 'database.yml')) {
$db_file_existed = true;
$db_settings = Ak::convert('yaml', 'array', AkConfig::getDir('config') . DS . 'database.yml');
}
$db_settings['sqlite_databases'] = array('database_file' => AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite', 'type' => 'sqlite');
file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings));
@unlink(AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite');
$this->installAndIncludeModels(array('TestOtherConnection'));
Ak::import('test_other_connection');
$OtherConnection = new TestOtherConnection(array('name' => 'Delia'));
$this->assertTrue($OtherConnection->save());
$this->installAndIncludeModels(array('DummyModel' => 'id,name'));
$Dummy = new DummyModel();
$this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection());
unset($db_settings['sqlite_databases']);
if ($db_file_existed) {
file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings));
} else {
unlink(AkConfig::getDir('config') . DS . 'database.yml');
}
}
示例6: populateTables
function populateTables()
{
$args = func_get_args();
$tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array();
foreach ($tables as $table){
$file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml';
if(!file_exists($file)){
continue;
}
$class_name = AkInflector::classify($table);
if($this->instantiateModel($class_name)){
$contents = &Ak::getStaticVar('yaml_fixture_'.$file);
if (!$contents) {
ob_start();
require_once($file);
$contents = ob_get_clean();
Ak::setStaticVar('yaml_fixture_'.$file, $contents);
}
$items = Ak::convert('yaml','array',$contents);
foreach ($items as $item){
$obj=&$this->{$class_name}->create($item);
if (isset($item['created_at'])) {
$obj->updateAttribute('created_at',$item['created_at']);
} else if (isset($item['created_on'])) {
$obj->updateAttribute('created_on',$item['created_on']);
}
}
}
}
}
示例7: _loadDbDesignerDbSchema
function _loadDbDesignerDbSchema()
{
if($path = $this->_getDbDesignerFilePath()){
$this->db_designer_schema = Ak::convert('DBDesigner','AkelosDatabaseDesign', Ak::file_get_contents($path));
return !empty($this->db_designer_schema);
}
return false;
}
示例8: toYaml
/**
* converts to yaml-strings
*
* examples:
* User::toYaml($users->find('all'));
* $Bermi->toYaml();
*
* @param array of ActiveRecords[optional] $data
*/
function toYaml($data = null)
{
return Ak::convert('active_record', 'yaml', empty($data) ? $this : $data);
}
示例9: parseXml
public function parseXml($xml_string)
{
return Ak::convert('xml', 'params_array', $xml_string);
}
示例10: parseMessageBody
private function parseMessageBody($data)
{
if (empty($data)) {
return array();
}
$content_type = $this->getContentType();
switch ($this->lookupMimeType($content_type)) {
case 'html':
$as_array = array();
parse_str($data, $as_array);
return $as_array;
case 'xml':
return Ak::convert('xml', 'params_array', $data);
break;
case 'json':
return json_decode($data, true);
default:
return array('put_body' => $data);
break;
}
}
示例11: test_html_to_text_using_smartipants
public function test_html_to_text_using_smartipants()
{
$html = <<<EOF
"I'm completelly agree"
EOF;
$markdown = <<<EOF
“I’m completelly agree”
EOF;
$this->assertEqual(Ak::convert('html', 'text', $html), $markdown);
}
示例12: _updateRemotePluginsList
/**
* Performs an update of available cached plugins.
*
* @return boolean
* @access private
*/
function _updateRemotePluginsList()
{
$new_plugins = array();
foreach ($this->getAvailableRepositories() as $repository){
$this->_addAvailablePlugins_($repository, $new_plugins);
}
if(empty($new_plugins)){
trigger_error(Ak::t('Could not fetch remote plugins from one of these repositories: %repositories', array('%repositories' => "\n".join("\n", $this->getAvailableRepositories()))), E_USER_NOTICE);
return false;
}
return Ak::file_put_contents($this->_getRepositoriesCahePath(), Ak::convert('array', 'yaml', $new_plugins));
}
示例13: getPossibleCases
static function getPossibleCases($options = array())
{
$default_options = array('config' => AK_TEST_DIR . DS . (AK_UNIT_TEST_SUITE_GLOBAL_NAMESPACE == 'Akelos' ? 'core_tests' : AkInflector::underscore(AK_UNIT_TEST_SUITE_GLOBAL_NAMESPACE)) . '.yml', 'base_path' => AK_TEST_DIR);
$options = array_merge($default_options, $options);
return array_map(array('AkInflector', 'camelize'), (array) array_keys(Ak::convert('yaml', 'array', file_get_contents($options['config']))));
}
示例14: loadFixture
function loadFixture($model_name)
{
if (!($fixture_file_name = $this->findFixtureForModel($model_name))) {
return false;
}
$Model = new $model_name();
$Fixture = array();
$items = Ak::convert('yaml', 'array', file_get_contents($fixture_file_name));
foreach ($items as $id => $item) {
$Record = $Model->create($item);
#we replace the 'id' with the returned value from the db
$item['id'] = $Record->getId();
$Fixture[$id] = new FixedActiveRecord($item, $Model);
}
return $this->{AkInflector::pluralize($model_name)} = $Fixture;
}
示例15: _compareXml
private function _compareXml($expected, $given)
{
$expected = Ak::convert('xml', 'array', $expected);
$given = Ak::convert('xml', 'array', $given);
$this->assertEqual($expected, $given);
}