I would like to use YUI compressor with minify PHP rather than the default JSmin. Does anyone have experience setting this up?
Right now I am using the groupsConfig.php to combine the JS.
return array(
'jsAll' => array('//contenido/themes/bam/assets/js/jquery.js', '//contenido/themes/bam/assets/js/modernizr.js','//contenido/themes/bam/assets/js/imgpreload.js', '//contenido/themes/bam/assets/js/imgpreload.js', '//contenido/themes/bam/assets/js/history.js','//contenido/themes/bam/assets/js/ajaxify.js', '//contenido/themes/bam/assets/js/isotope.js'),
'jsHome' => array('//contenido/themes/bam/assets/js/easing.js','//contenido/themes/bam/assets/js/scrollable.js', '//contenido/themes/bam/assets/js/home.js'),
'cssAll' => array('//contenido/themes/bam/bam.css'),
);
As it says on the homepage:
Uses an enhanced port of Douglas Crockford's JSMin library and custom classes to minify CSS and HTML
I have the following code in config.php, but I get a 500 error when trying to view the combined js file:
function yuiJs($js) {
require_once '/lib/Minify/YUICompressor.php';
Minify_YUICompressor::$jarFile = '/lib/yuicompressor-2.4.2.jar';
Minify_YUICompressor::$tempDir = '/temp';
return Minify_YUICompressor::minifyJs($js);
}
$min_serveOptions['minifiers']['application/x-javascript'] = 'yuiJs';
It also appears that there are several lines in lib/Minify/YUICompressor.php that need to be configured, and I'm not sure if I'm doing it right:
class Minify_YUICompressor {
/**
* Filepath of the YUI Compressor jar file. This must be set before
* calling minifyJs() or minifyCss().
*
* #var string
*/
public static $jarFile = '../yuicompressor-2.4.2.jar';
/**
* Writable temp directory. This must be set before calling minifyJs()
* or minifyCss().
*
* #var string
*/
public static $tempDir = '../../temp/';
/**
* Filepath of "java" executable (may be needed if not in shell's PATH)
*
* #var string
*/
public static $javaExecutable = 'java';
I had the same problem on windows. It seems jar file needs to be executable in order to run yui compressor. So, i have to remove excutable check from YUICompressor.php
#132
private static function _prepare()
{
if (! is_file(self::$jarFile)) {
throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not a valid file.');
}
// if (! is_executable(self::$jarFile)) {
// throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not executable.');
// }
if (! is_dir(self::$tempDir)) {
throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not a valid direcotry.');
}
if (! is_writable(self::$tempDir)) {
throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not writable.');
}
}
and that works fine.
Related
I was wondering if there is a way to load different folder based on php version. I could do it writing my own autoloader, but i was wondering if there is a way of using composer for that?
Ps. I have seen this in use before in module / plugin application that where redistributed globally to work with wide range of env. Those scripts where using own autoloading classes.
I am curios is there a way to use composer in similar way.
Scenario: class / folder structure:
class >
php5.6 >
- SomeClass.php
...
php7.x >
- SomeClass.php
...
php8.x >
- SomeClass.php
...
Compare php version and do something:
$classPathForAutoloader = '';
if (version_compare(PHP_VERSION, '8.0.0') >= 0) {
$classPathForAutoloader = 'php8.x';
// do something to composer autoload or
// use declaration
}else if(version_compare(PHP_VERSION, '7.0.0') >= 0){
$classPathForAutoloader = 'php7.x';
// do something to composer autoload or
// use declaration
}else if(version_compare(PHP_VERSION, '5.6.0') >= 0{
$classPathForAutoloader = 'php5.6';
// do something to composer autoload or
// use declaration
}else{
// throw Exception ...
}
standard composer setup:
{
"name": "some/name",
"require": {
},
"authors": [
{
"name": "Some Name",
"email": "some#email.com"
}
],
"autoload": {
"psr-4": {
"Devwl\\": "class/",
"Tools\\": "tools/"
},
"classmap": [
"class/"
],
"exclude-from-classmap": []
}
}
I don't think Composer provides a way to dynamically autoload different paths.
Can you use version_compare in a single SomeClass.php class only where the functionality differs by PHP version? Or write the entire SomeClass.php to be backwards compatible?
To me loading different classes depending on the PHP version is asking for trouble when it comes to reproducibility across environments.
Another option would be to use require_once to load the different classes, but for maintainability I'd really lean towards a single class with version checks only when absolutely necessary.
So i have created a class which does what I need. It can laso work alongside Composer autoloader.
<?php
class PhpVersionAutoloader{
private $baseClassesDirPath = null;
private $phpVersionArr = [];
private $phpDir = null;
private $classes = []; /** Keep a record of all loaded classes */
/**
* Allows to change base dir path.
* If not set the path will be set to file _DIR_
*
* #see $this->baseClassesDirPath
*
* #param string $path
* #return void
*/
public function setBaseClassesDirPath($path)
{
$this->baseClassesDirPath = $path;
}
/**
* Map available dir name and php version
*
* #see $this->phpVersionArr
*
* #param string $directory name
* #param string $phpVersion
* #return void
*/
public function registerPhpDir($dir, $phpVersion){
$this->phpVersionArr[] = [$dir => $phpVersion];
}
/**
* Compare curent php version with $this->phpVersionArr to determin the right path for class load
*/
public function selectPhpDir(){
foreach ($this->phpVersionArr as $key => $phpVDir) {
$this->position = $key;
foreach($phpVDir as $key => $value){
if (version_compare(PHP_VERSION, $value) >= 0){
$this->phpDir = $key;
break 2;
}
}
}
}
/**
* Register autloader
*
* #return void
*/
public function register(){
spl_autoload_register(function($className)
{
$namespace = str_replace("\\","/",__NAMESPACE__);
$className = str_replace("\\","/",$className);
$this->baseClassesDirPath = ($this->baseClassesDirPath === null) ? str_replace("\\","/",__DIR__) : $this->baseClassesDirPath;
$class = $this->baseClassesDirPath."/classes/".$this->phpDir.'/'. (empty($namespace)?"":$namespace."/")."{$className}.php";
$this->classes[] = $class;
if (file_exists($class)){
include_once($class);
}else{
// ... if not exsist try to load lower php version file?
// ... or throw new Error("Error Processing Request", 1);
}
});
}
}
Use the PhpVersionAutoloader object like this:
/**
* Use example
*/
$loader = new PhpVersionAutoloader(); // init PhpVersionAutoloader object
$loader->setBaseClassesDirPath('C:/xampp/htdocs/blog/blog autoloading'); // if not used will use _DIR_ to create path
$loader->registerPhpDir('php8.x', '8.0.0'); // as "folder name" => "php version"
$loader->registerPhpDir('php7.x', '7.0.0'); // ...
$loader->registerPhpDir('php5.6', '5.6.0'); // ...
$loader->selectPhpDir(); // compare system php version and selects the correct phpX.X subfolder
$loader->register(); // register autoloader
I also created more functional class of this loader which allow to force specific directory to load from or even allow to load classes from older version of PHP if not found in selected version.
See github [here]
How can I compile a blade template from a string rather than a view file, like the code below:
<?php
$string = '<h2>{{ $name }}</h2>';
echo Blade::compile($string, array('name' => 'John Doe'));
?>
http://paste.laravel.com/ujL
I found the solution by extending BladeCompiler.
<?php namespace Laravel\Enhanced;
use Illuminate\View\Compilers\BladeCompiler as LaravelBladeCompiler;
class BladeCompiler extends LaravelBladeCompiler {
/**
* Compile blade template with passing arguments.
*
* #param string $value HTML-code including blade
* #param array $args Array of values used in blade
* #return string
*/
public function compileWiths($value, array $args = array())
{
$generated = parent::compileString($value);
ob_start() and extract($args, EXTR_SKIP);
// We'll include the view contents for parsing within a catcher
// so we can avoid any WSOD errors. If an exception occurs we
// will throw it out to the exception handler.
try
{
eval('?>'.$generated);
}
// If we caught an exception, we'll silently flush the output
// buffer so that no partially rendered views get thrown out
// to the client and confuse the user with junk.
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
}
}
Small modification to the above script.
You can use this function inside any class without extending the BladeCompiler class.
public function bladeCompile($value, array $args = array())
{
$generated = \Blade::compileString($value);
ob_start() and extract($args, EXTR_SKIP);
// We'll include the view contents for parsing within a catcher
// so we can avoid any WSOD errors. If an exception occurs we
// will throw it out to the exception handler.
try
{
eval('?>'.$generated);
}
// If we caught an exception, we'll silently flush the output
// buffer so that no partially rendered views get thrown out
// to the client and confuse the user with junk.
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
}
For anyone still interested in this, they've added it to Laravel 9
use Illuminate\Support\Facades\Blade;
return Blade::render('Hello, {{ $name }}', ['name' => 'Julian Bashir']);
https://laravel.com/docs/9.x/blade#rendering-inline-blade-templates
I just stumbled upon the same requirement! For me, i had to fetch a blade template stored in DB & render it to send email notifications.
I did this in laravel 5.8 by kind-of Extending \Illuminate\View\View. So, basically i created the below class & named him StringBlade (I couldn't find a better name atm :/)
<?php
namespace App\Central\Libraries\Blade;
use Illuminate\Filesystem\Filesystem;
class StringBlade implements StringBladeContract
{
/**
* #var Filesystem
*/
protected $file;
/**
* #var \Illuminate\View\View|\Illuminate\Contracts\View\Factory
*/
protected $viewer;
/**
* StringBlade constructor.
*
* #param Filesystem $file
*/
public function __construct(Filesystem $file)
{
$this->file = $file;
$this->viewer = view();
}
/**
* Get Blade File path.
*
* #param $bladeString
* #return bool|string
*/
protected function getBlade($bladeString)
{
$bladePath = $this->generateBladePath();
$content = \Blade::compileString($bladeString);
return $this->file->put($bladePath, $content)
? $bladePath
: false;
}
/**
* Get the rendered HTML.
*
* #param $bladeString
* #param array $data
* #return bool|string
*/
public function render($bladeString, $data = [])
{
// Put the php version of blade String to *.php temp file & returns the temp file path
$bladePath = $this->getBlade($bladeString);
if (!$bladePath) {
return false;
}
// Render the php temp file & return the HTML content
$content = $this->viewer->file($bladePath, $data)->render();
// Delete the php temp file.
$this->file->delete($bladePath);
return $content;
}
/**
* Generate a blade file path.
*
* #return string
*/
protected function generateBladePath()
{
$cachePath = rtrim(config('cache.stores.file.path'), '/');
$tempFileName = sha1('string-blade' . microtime());
$directory = "{$cachePath}/string-blades";
if (!is_dir($directory)) {
mkdir($directory, 0777);
}
return "{$directory}/{$tempFileName}.php";
}
}
As you can already see from the above, below are the steps followed:
First converted the blade string to the php equivalent using \Blade::compileString($bladeString).
Now we have to store it to a physical file. For this storage, the frameworks cache directory is used - storage/framework/cache/data/string-blades/
Now we can ask \Illuminate\View\Factory native method 'file()' to compile & render this file.
Delete the temp file immediately (In my case i didn't need to keep the php equivalent file, Probably same for you too)
And Finally i created a facade in a composer auto-loaded file for easy usage like below:
<?php
if (! function_exists('string_blade')) {
/**
* Get StringBlade Instance or returns the HTML after rendering the blade string with the given data.
*
* #param string $html
* #param array $data
* #return StringBladeContract|bool|string
*/
function string_blade(string $html, $data = [])
{
return !empty($html)
? app(StringBladeContract::class)->render($html, $data)
: app(StringBladeContract::class);
}
}
Now i can call it from anywhere like below:
<?php
$html = string_blade('<span>My Name is {{ $name }}</span>', ['name' => 'Nikhil']);
// Outputs HTML
// <span>My Name is Nikhil</span>
Hope this helps someone or at-least maybe inspires someone to re-write in a better way.
Cheers!
I'm not using blade this way but I thought that the compile method accepts only a view as argument.
Maybe you're looking for:
Blade::compileString()
It's a old question. But I found a package which makes the job easier.
Laravel Blade String Compiler renders the blade templates from the string value. Check the documentation on how to install the package.
Here is an example:
$template = '<h1>{{ $name }}</h1>'; // string blade template
return view (['template' => $template], ['name' => 'John Doe']);
Note: The package is now updated to support till Laravel 6.
I know its pretty old thread, but today also requirement is same.
Following is the way I solved this on my Laravel 5.7 (but this will work with any laravel version greater than version 5), I used the knowledge gained from this thread and few other threads to get this working (will leave links to all threads at the end, if this help up-vote those too)
I added this to my helper.php (I used this technique to add helper to my project, but you can use this function directly as well)
if (! function_exists('inline_view')) {
/**
* Get the evaluated view contents for the given blade string.
*
* #param string $view
* #param array $data
* #param array $mergeData
* #return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
*/
function inline_view($view = null, $data = [], $mergeData = [])
{
/* Create a file with name as hash of the passed string */
$filename = hash('sha1', $view);
/* Putting it in storage/framework/views so that these files get cleared on `php artisan view:clear*/
$file_location = storage_path('framework/views/');
$filepath = storage_path('framework/views/'.$filename.'.blade.php');
/* Create file only if it doesn't exist */
if (!file_exists($filepath)) {
file_put_contents($filepath, $view);
}
/* Add storage/framework/views as a location from where view files can be picked, used in make function below */
view()->addLocation($file_location);
/* call the usual view helper to render the blade file created above */
return view($filename, $data, $mergeData);
}
}
Usage is exactly same as laravel's view() helper, only that now first parameter is the blade string
$view_string = '#if(strlen($name_html)>6)
<strong>{{ $name_html }}</strong>
#else
{{$name_html}}
#endif';
return inline_view($view_string)->with('name_html', $user->name);
return inline_view($view_string, ['name_html' => $user->name]);
References:
https://stackoverflow.com/a/31435824/4249775
https://stackoverflow.com/a/33594452/4249775
Laravel 9 :
use Illuminate\Support\Facades\Blade;
return Blade::render('Your Blade Content {{ $parameter1}}', ['parameter1' => 'Name']);
Warning: Parameter 3 to showBlogSection() expected to be a reference, value given in /home/smartsta/public_html/includes/Cache/Lite/Function.php on line 100
I'm getting the above error displaying within my content areas on my Joomla site all a sudden, any suggestions?
Update: No such luck finding access to defined file and directory within godaddy ftp file directory, ftp, or Joomal C-panel.
Within FTP, I cannot find access to this particular file to investigate what is on line 100.
Within the Joomla panel, in Global Configurations, I was able to toggle 'error message' to none for atleast this error to be hidden. Within the cache directory I do not see any options to get into the folder, though it displays.
I also see this at the bottom of that c-panel screen, but just links to a joomla help site, and within the fields I do not see described area to toggle 'ON or OFF'
"Following PHP Server Settings are not optimal for Security and it is recommended to change them:
PHP register_globals setting is ON instead of OFF
"
Update2!:
I've found the file in question, below is the code. Line 100 only states:
global $$object_123456789;
application/x-httpd-php Function.php
PHP script text
<?php
/**
* This class extends Cache_Lite and can be used to cache the result and output of functions/methods
*
* This class is completly inspired from Sebastian Bergmann's
* PEAR/Cache_Function class. This is only an adaptation to
* Cache_Lite
*
* There are some examples in the 'docs/examples' file
* Technical choices are described in the 'docs/technical' file
*
* #package Cache_Lite
* #version $Id: Function.php 47 2005-09-15 02:55:27Z rhuk $
* #author Sebastian BERGMANN <sb#sebastian-bergmann.de>
* #author Fabien MARTY <fab#php.net>
*/
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
require_once( $mosConfig_absolute_path . '/includes/Cache/Lite.php' );
class Cache_Lite_Function extends Cache_Lite
{
// --- Private properties ---
/**
* Default cache group for function caching
*
* #var string $_defaultGroup
*/
var $_defaultGroup = 'Cache_Lite_Function';
// --- Public methods ----
/**
* Constructor
*
* $options is an assoc. To have a look at availables options,
* see the constructor of the Cache_Lite class in 'Cache_Lite.php'
*
* Comparing to Cache_Lite constructor, there is another option :
* $options = array(
* (...) see Cache_Lite constructor
* 'defaultGroup' => default cache group for function caching (string)
* );
*
* #param array $options options
* #access public
*/
function Cache_Lite_Function($options = array(NULL))
{
if (isset($options['defaultGroup'])) {
$this->_defaultGroup = $options['defaultGroup'];
}
$this->Cache_Lite($options);
}
/**
* Calls a cacheable function or method (or not if there is already a cache for it)
*
* Arguments of this method are read with func_get_args. So it doesn't appear
* in the function definition. Synopsis :
* call('functionName', $arg1, $arg2, ...)
* (arg1, arg2... are arguments of 'functionName')
*
* #return mixed result of the function/method
* #access public
*/
function call()
{
$arguments = func_get_args();
$id = serialize($arguments); // Generate a cache id
if (!$this->_fileNameProtection) {
$id = md5($id);
// if fileNameProtection is set to false, then the id has to be hashed
// because it's a very bad file name in most cases
}
$data = $this->get($id, $this->_defaultGroup);
if ($data !== false) {
$array = unserialize($data);
$output = $array['output'];
$result = $array['result'];
} else {
ob_start();
ob_implicit_flush(false);
$target = array_shift($arguments);
if (strstr($target, '::')) { // classname::staticMethod
list($class, $method) = explode('::', $target);
$result = call_user_func_array(array($class, $method), $arguments);
} else if (strstr($target, '->')) { // object->method
// use a stupid name ($objet_123456789 because) of problems when the object
// name is the same as this var name
list($object_123456789, $method) = explode('->', $target);
global $$object_123456789;
$result = call_user_func_array(array($$object_123456789, $method), $arguments);
} else { // function
$result = call_user_func_array($target, $arguments);
}
$output = ob_get_contents();
ob_end_clean();
$array['output'] = $output;
$array['result'] = $result;
$this->save(serialize($array), $id, $this->_defaultGroup);
}
echo($output);
return $result;
}
}
?>
It is not exactly an error. It is a warning.
Suddenly? Perhaps you have upgraded/updated your PHP version. Or changed PHP configuration to "strict mode".
The message "expected to be a reference, value given" means the called function expected to receive a reference, not a value. Look:
$something = 9;
show_section($something);
// here you are passing a variable
// this will be accepted as a reference
show_section(9);
// here you are NOT passing a reference
// here you are passing a VALUE
When you pass "by reference", the function can change the variable value... in the example above:
function show_section(&$parameter) {
$parameter = 'changed!';
}
Note the ampersand symbol & before the $parameter - this is how we specify a function requires a REFERENCE.
AFTER the function call, in the example above, the variable $something value will be the changed! string.
The line throwing the error is NOT the "global" one. It is the next:
$result = call_user_func_array(array($$object_123456789, $method), $arguments);
The problem here is that the function is being called indirectly by using the "call_user_func_array" function.
A solution would be transforming all arguments into references. Suggestion:
foreach ($arguments as $count => $value)
{
$param = 'param' . $count;
$$param = $value;
$arguments[$count] = &$$param;
}
Put the code above in the beginning of the call function, right after the following line:
$id = serialize($arguments);
Give this a try!
I added one library for gettext translation. Added corresponding po and mo files.
And the translation is working fine.
Now when I update my po file, change some translation.. after that when I reload the page, I am getting the old translation, not the new.
Here is the Library code:
/**
* This method overides the original load method. Its duty is loading the domain files by config or by default internal settings.
*
*/
function load_gettext($userlang = false) {
/* I want the super object */
if ($userlang)
$this->gettext_language = $userlang;
else
$this->gettext_language = 'it_IT';
log_message('debug', 'Gettext Class gettext_language was set by parameter:' . $this->gettext_language);
putenv("LANG=$this->gettext_language");
setlocale(LC_ALL, $this->gettext_language);
/* Let's set the path of .po files */
$this->gettext_path = APPPATH . 'language/locale';
log_message('debug', 'Gettext Class path chosen is: ' . $this->gettext_path);
bindtextdomain($this->gettext_domain, $this->gettext_path);
textdomain($this->gettext_domain);
log_message('debug', 'Gettext Class the domain chosen is: ' . $this->gettext_domain);
return true;
}
/**
* Plural forms added by Tchinkatchuk
* http://www.codeigniter.com/forums/viewthread/2168/
*/
/**
* The translator method
*
* #param string $original the original string to translate
* #param array $aParams the plural parameters
* #return the string translated
*/
function _trans($original, $aParams = false) {
if (isset($aParams['plural']) && isset($aParams['count'])) {
$sTranslate = ngettext($original, $aParams['plural'], $aParams['count']);
$sTranslate = $this->replaceDynamically($sTranslate, $aParams);
} else {
$sTranslate = gettext($original);
if (is_array($aParams) && count($aParams))
$sTranslate = $this->replaceDynamically($sTranslate, $aParams);
}
return $sTranslate;
}
This is the usage in a controller:
$this->pos_language->load_gettext('fr_FR');
echo $this->pos_language->_trans('Hello world, good morning');
I think you need to compile your .po files to .mo files. Gettext uses the .mo file, the .po is just a human readable form.
If you haven't done the compilation step, your application is still reading your old .mo files, with the untranslated strings...
This page has some more info about gettext translation: http://wiki.creativecommons.org/Translating_PO_Files
I wrote a helper to integrate php-gettext with Smarty & Code Igniter 2
http://bit.ly/rrITVx
I hope it might help
I need to send/return objects or array to/from PHP using SOAP. Any good links?
I am using Zend_Soap_Server и Zend_Soap_Client. I send/receive array of difficult structure.
At first create class with structure you want to receive.
<?php
/**
* Information about people
*/
class PeopleInformation
{
/**
* Name of ...
*
* #var string
*/
public $name;
/**
* Age of
* #var int
*/
public $age;
/**
* Array of family
*
* #var FamilyInformation[]
*/
public $family;
}
/**
* Information about his family
*/
class FamilyInformation
{
/**
* Mother/sister/bro etc
*
* #var string
*/
public $relation;
/**
* Name
* #var string
*/
public $name;
}
?>
Then create service to receive this data:
<?php
/**
* Service to receive SOAP data
*/
class SoapService
{
/**
*
* #param PeopleInformation $data
* #return string
*/
public function getUserData($data)
{
//here $data is object of PeopleInformation class
return "OK";
}
}
?>
Now create Zend_Soap_Server instance in controller by url http://ourhost/soap/:
<?php
//disable wsdl caching
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache', 0);
$wsdl = $_GET['wsdl'];
//this generate wsdl from our class SoapService
if (!is_null($wsdl))
{
$autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
$autodiscover->setClass('SoapService');
$autodiscover->handle();
}
//handle all soap request
else
{
$wsdlPath = 'http://ourhost/soap/?wsdl';
$soap = new Zend_Soap_Server($wsdlPath, array(
'cache_wsdl' => false
));
$soap->registerFaultException('Zend_Soap_Server_Exception');
$soap->setClass('SoapService');
$soap->handle();
}
?>
And now you get wsdl (http://ourhost/soap/?wsdl) with you structure and handle request in SoapService::getUserData. Input parametr in this method is object of PeopleInformation class
Basically you need to create a class map and pass it to your soap client. Yes it is a pain. I usually just have a method that maps the Soap Object name to PHP objects (i.e. Person => MY_Person) and only code the ones I need to by hand (i.e createdOn => DateTime).
class MY_WSHelper
{
protected static $ws_map;
public static function make_map()
{
if( ! self::$ws_map)
{
self::$ws_map = array();
//These will be mapped dynamically
self::$ws_map['Person'] = NULL;
self::$ws_map['Animal'] = NULL;
//Hard-coded type map
self::$ws_map['createdOn'] = DateTime;
self::$ws_map['modifiedOn'] = DateTime;
foreach(self::$ws_map as $soap_name => $php_name)
{
if($php_name === NULL)
{
//Map un-mapped SoapObjects to PHP classes
self::$ws_map[$soap_name] = "MY_" . ucfirst($soap_name);
}
}
}
return self::$ws_map;
}
}
Client:
$client = new SoapClient('http://someurl.com/personservice?wsdl',
array('classmap' => MY_WSHelper::make_map()));
$aperson = $client->getPerson(array('name' => 'Bob'));
echo get_class($aperson); //MY_Person
echo get_class($aperson->createdOn); //DateTime
http://php.net/manual/en/soapclient.soapclient.php
Papa Google points me to this Zend article with lots of good examples on both the client and server aspects of working with Soap (in particular PHP5's implementation of it). Looks like a good starting point.
If you're somewhat like me, and cringe at the thought of writing up a WSDL by hand, I'd recommend using WSHelper, which uses PHP's reflection classes to dynamically generate a WSDL for you. Definitely a time-saver
I replay to share my (bad) experience.
I've created a webservice using PHP ZendFramework2 (ZF2).
The server reply objects and array of objects, and until it taken string as input it worked well. I was using the ArrayOfTypeComplex strategy.
$_strategy = new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex();
When I try to use an array of string as input I felt in a dark and unhappy valley until I found Ramil's answer, so I change strategy and all work right!
$_strategy = new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence();
if (isset($_GET['wsdl'])) {
$autodiscover = new \Zend\Soap\AutoDiscover($_strategy);
$autodiscover->setBindingStyle(array('style' => 'document'));
$autodiscover->setOperationBodyStyle(array('use' => 'literal'));
$autodiscover->setClass('Tracker\Queue\Service')
->setUri($_serverUrl);
echo $autodiscover->toXml();
}