I would like to return an array of string in my web services
I've tryed :
<?php
require_once('nusoap/nusoap.php');
$server = new soap_server();
$server->configureWSDL('NewsService', 'urn:NewsService');
$server->register('GetAllNews',
array(),
array('return' => 'xsd:string[]'),
'urn:NewsService',
'urn:NewsService#GetAllNews',
'rpc',
'literal',
''
);
// Define the method as a PHP function
function GetAllNews()
{
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
return $stack;
}
but it doesn't work. What is the correct syntax for that ?
Thanks in advance for any help
You first need to define a new type that describes an array of strings like so:
$server->wsdl->addComplexType(
'ArrayOfString',
'complexType',
'array',
'sequence',
'',
array(
'itemName' => array(
'name' => 'itemName',
'type' => 'xsd:string',
'minOccurs' => '0',
'maxOccurs' => 'unbounded'
)
)
);
Then you can use tns:ArrayOfString as the return type.
This site describes a nice way to return complex datatypes and receive it with C#: http://sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html
When returning array of arrays, you might need a different configuration from Oliver. For example phfunc2php uses this technique in the nusoapcode.class.php file (https://github.com/sylnsr/pgfunc2php/blob/master/nusoapcode.class.php). The code it generates looks like so:
$server->wsdl->addComplexType(
'ArrayOfArrays','complexType','array','',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')));
and then the functions simply needs to return "tnsArrayOfArrays:
$server->register(
'sel_signon_id_by_uuid',
array('user_uuid' => 'xsd:string'),
array('return'=>'tns:ArrayOfArrays'),
The project mentioned above can compile working code for you, should you want to see this.
Related
I am trying to update a legacy php code (7.0) for php 7.4 >=
and one of the new features that I would like to use the new fn() => syntax, instead of function() use () {}
Unfortunately, I have hundreds of anonymous functions using CakePHP ORM like:
$query->matching('Tags', function ($q) {
return $q->where(['Tags.name' => 'CakePHP']);
});
Using php 7.4 >= could be:
$query->matching('Tags', fn($q) =>
$q->where(['Tags.name' => 'CakePHP'])
);
Sometimes using "use":
$query = $articles->find()->matching('Comments.Users', function ($q) use ($username) {
return $q->where(['username' => $username]);
});
php 7.4 >= (use is not needed):
$query = $articles->find()->matching('Comments.Users', fn ($q) =>
$q->where(['username' => $username])
);
Or using two or more params:
$query->where(function (QueryExpression $exp, Query $q) {
return $exp->eq('published', true);
});
But when you have more than one instruction, fn () cannot be used, for example:
$results->map(function ($row) {
$row['age'] = $row['birth_date']->diff(new \DateTime)->y;
return $row;
});
I would like to use notepad++ regex and replace in all files feature to execute a regex and replace all "possible" functions() for fn().
So, What REGEX could achieve this goal?
Find: function\s*\(([^\(\)]*)\)[^\{]*\{\s*return\s*([^;]*)\s*;\s*\}
Replace: fn\(\1\) => \2
question is very simple, is there a quick way to translate a preloaded list in db. For example list of towns/countries?
class SeedTownTable extends Seeder
public function run()
{
$town_list = array(
'Акко',
'Арад',
'Ариэль',
'Афула',
'Ашдод',
'Ашкелон',
'Бат-Ям',
'Бейт-Шеан',
'Бейт-Шемеш',
'Бейтар-Илит',
'Беэр-Шева',
'Бней-Брак',
'Герцлия',
'Гиват-Шмуэль',
'Кирьят-Малахи',
'Кирьят-Моцкин',
'Кирьят-Оно',
'Кирьят-Тивон',
'Кирьят-Хаим',
'Кирьят-Шмона',
'Кирьят-Ям',
'Кфар-Саба',
'Лод',
'Маале-Адумим',
'Маалот-Таршиха',
'Метула',
'Мигдаль-ха-Эмек',
'Модиин',
'Ход-ха-Шарон',
'Холон',
'Цфат',
'Эйлат',
'Эльад',
'Явне',
'Яффо'
);
foreach ( $town_list as $town ){
Town::create([
'name' => $town
]);
}
}
I made towns model with records without any backend controller.
And I want to translate this list.
thanks.
Add the translation to your data array and use setAttributeTranslated to add the translated version.
As mentioned in the Docs
// Gets a single translated attribute for a language
$user->getAttributeTranslated('name', 'fr');
// Sets a single translated attribute for a language
$user->setAttributeTranslated('name', 'Jean-Claude', 'fr');
Try
$town_list = array(
[
'name' => 'Town Name Default Lang',
'name-es' => 'Town Name in Spanish',
]
...
)
foreach ( $town_list as $town ){
$t = new TownModel();
$t->name = $town['name'];
$t->setAttributeTranslated('name', $town['name-es'], 'es');
$t->save();
}
While calling getInsights() method,it gives an object.so i want to access some data from it.
Here is the api call
$account->getInsights($fields, $params);
echo '<pre>';print_r($resultArr);die;
it will gives result like
FacebookAds\Cursor Object
(
[response:protected] => FacebookAds\Http\Response Object
(
[request:protected] => FacebookAds\Http\Request Object
(
[client:protected] => FacebookAds\Http\Client Object
(
[requestPrototype:protected] => FacebookAds\Http\Request Object
(
Thanks in advance.
The following should work:
$resultArr = $account->getInsights($fields, $params)[0]->getData();
echo '<pre>';
print_r($resultArr);
die;
If you have more than one object in the cursor, you can just loop over it:
foreach ($account->getInsights($fields, $params) as $obj) {
$resultArr = $obj->getData();
echo '<pre>';
print_r($resultArr);
}
die;
In this case, if you set the implicitFetch option to true by default with:
Cursor::setDefaultUseImplicitFetch(true);
you will be sure you are looping over all the results.
I using this piece of code and It works for me, I hope works for you ...
$adset_insights = $ad_account->getInsights($fields,$params_c);
do {
$adset_insights->fetchAfter();
} while ($adset_insights->getNext());
$adsets = $adset_insights->getArrayCopy(true);
Maybe try:
$insights = $account->getInsights($fields, $params);
$res = $insights->getResponse()->getContent();
and then go for the usual stuff:
print_r($res['data']);
Not sure if my method differs from Angelina's because it's a different area of the SDK or if it's because it's been changed since her answer, but below is the code that works for me, and hopefully will be useful for someone else:
$location_objects = $cursor->getArrayCopy();
$locations = array();
foreach($location_objects as $loc)
{
$locations[] = $loc->getData();
}
return $locations;
Calling getArrayCopy returns an array of AbstractObjects and then calling getData returns an an array of the objects props.
I get a 'parameter count mismatch' TargetParameterCountException when I want to test my Tenant repository:
The interface:
public interface ITenantRepository
{
IQueryable<Tenant> Get(Expression<Func<Tenant, bool>> filter = null,
Func<IQueryable<Tenant>, IOrderedQueryable<Tenant>> orderBy = null,
string includeProperties = null);
}
The test code:
var TenantRepository = new Mock<ITenantRepository>();
TenantRepository
.Setup(p => p.Get(It.IsAny<Expression<Func<Tenant, bool>>>(),
It.IsAny<Func<IQueryable<Tenant>,IOrderedQueryable<Tenant>>>() ,
It.IsAny<string>()))
.Returns(new Func<Expression<Func<Tenant, bool>>,
IQueryable<Tenant>>(expr => Tenants.Where(expr.Compile()).AsQueryable()));
Tenant TestTenant = TenantRepository.Object.Get(
t => t.TenantID == Tenant2.TenantID,
null,
null).FirstOrDefault();
The error occurs on the last line.
Found the solution for the correct parameters:
TenantRepository.Setup(p => p.Get(It.IsAny<Expression<Func<Tenant, bool>>>(),
It.IsAny<Func<IQueryable<Tenant>, IOrderedQueryable<Tenant>>>(),
It.IsAny<string>()))
.Returns(
(Expression<Func<Tenant, bool>> expr,
Func<IQueryable<Tenant>, IOrderedQueryable<Tenant>> orderBy,
string includeProperties) => Tenants.Where(expr.Compile()).AsQueryable());
I believe the problem resides in the return type of your mocked object: according to your interface, the method Get should return an IQueryable, but you are mocking it to return a Func<Expression<Func<Tenant, bool>>, IQueryable<Tenant>> instead.
Just keep in mind that returning a function is different from returning its result; in this case, you should create an expected IQueryable object and just tell Moq to return it. It doesn't make much sense to mock something using its expected behaviour - which looks like what you are trying to do here.
Pretty straight forward question:
I have page--front.tpl and page.tpl template pages in use in a drupal 7 site. However, I'd like to use page-front.tpl on one other page. Is this possible or do I need to create another .tpl page to do this.
The site I'm working on is split into two sections, it's essentially two seperate websites that you can flip between whether your a consumer or business owner. So I want to use the front.tpl template for the home page of each site.
Cheers.
You can add theme_preprocess_page function to your theme's template.php file and then add your template name in templates suggestions list.
function mytheme_preprocess_page(&$vars) {
// you can perform different if statements
// if () {...
$template = 'page__front'; // you should replace dash sign with underscore
$vars['theme_hook_suggestions'][] = $template;
// }
}
EDIT
If you want to specify template name by path alias, you could write code like this:
function phptemplate_preprocess_page(&$variables) {
if (module_exists('path')) {
$alias = drupal_get_path_alias($_GET['q']);
if ($alias != $_GET['q']) {
$template = 'page_';
foreach (explode('/', $alias) as $part) {
$template.= "_{$part}";
$variables['theme_hook_suggestions'][] = $template;
}
}
}
}
Without this function you would have the following node template suggestions by default:
array(
[0] => page__node
[1] => page__node__%
[2] => page__node__1
)
And this function would apply to your node the following new template suggestions.
Example node with node/1 path and page/about alias:
array(
[0] => page__node
[1] => page__node__%
[2] => page__node__1
[3] => page__page
[4] => page__page_about
)
So after that you can use page--page-about.tpl.php for your page.
If you want to apply page--front.tpl.php to your let's say node/15, then in this function you can add if statement.
function phptemplate_preprocess_page(&$variables) {
if (module_exists('path')) {
$alias = drupal_get_path_alias($_GET['q']);
if ($alias != $_GET['q']) {
$template = 'page_';
foreach (explode('/', $alias) as $part) {
$template.= "_{$part}";
$variables['theme_hook_suggestions'][] = $template;
}
}
}
if ($_GET['q'] == 'node/15') {
$variables['theme_hook_suggestions'][] = 'page__front';
}
}
This would give you the following template suggestions:
array(
[0] => page__node
[1] => page__node__%
[2] => page__node__1
[3] => page__page
[4] => page__page_about
[5] => page__front
)
The highest index - the highest template priority.