In SiteContoller::beforeWebMethod(), I can’t help thinking that this:
if (! Yii::app()->user->isGuest || in_array($service->methodName, $safeMethods))
is easier than this:
$pattern='/^('.implode('|',$safeMethods).')$/i';
if(!Yii::app()->user->isGuest || preg_match($pattern,$service->methodName))
Also, would it not make more sense to throw a SoapFault on login failure?
public function login($username, $password) {
$identity = new UserIdentity($username, $password);
if ($identity->authenticate())
Yii::app()->user->login($identity);
else
throw new CException('Login attempt failed');
}
And, finally, if someone is interested in a SOAP client test script to run outside of Yii:
<?php
class Contact {
public $id;
}
$wsdlUrl = 'http://your_host_here/yii/demos/phonebook/index.php?r=site/phonebook';
$client = new SoapClient($wsdlUrl);
echo "Logging in...\n";
try {
$client->login('demo','demo');
} catch (SoapFault $e) {
echo 'Caught SOAP fault: '. $e->getMessage(); exit(1);
}
echo "fetching all contacts\n";
print_r($client->getContacts());
echo "\ninserting a new contact...\n\n\n";
$contact = new Contact;
$contact->name = 'Mr Soap Client';
$contact->phone = '123-999-1234';
try {
$client->saveContact($contact);
} catch (SoapFault $e) {
echo 'Caught SOAP fault: '. $e->getMessage(); exit(1);
}
echo "done\n\n";
echo "fetching all contacts\n";