Configuration to use php intl package in Laravel 8 - php

I have followed the first answer solution of this question Installing PHP intl extension , so I have introduced in composer the line "ext-intl": "*", and run composer update (everything went smooth), but when I try to use within my controller $collator = locale_get_default(); I receive the following answer:
Error
Call to undefined function App\Http\Controllers\locale_get_default()
I do not know how to link my code to the ext-intl package that I have added to the composer configuration.
Thanks in advance for your help.
--
Thank you for your answer Sergio. I have realized that in the web server the php-intl is operative, so I only need to install it in my development environment (XAMPP over OSx: I will find out and come back). But now a new question has came out, thus:
Even in my web server (where php-intl is running) it seems that there is no effective link between the php and the Laravel levels. I have arrived to this conclusion (that surprises me), because if I make a change in the locale with php, it seems not to take place in Laravel Level. Example:
If I run the following (being the server configuration "en_US"):
setlocale(LC_ALL, "es_ES.utf8");
$collator = locale_get_default();
dd($collator);
the output is "es_ES", but if I run:
setlocale(LC_ALL, "es_ES.utf8");
dd(App::currentLocale());
the output is "en".
By the other side, if I run:
App::setLocale('es');
dd(App::currentLocale());
the output is "es". But if I run:
App::setLocale('es');
$collator = locale_get_default();
dd($collator);
the output is " en_US_POSIX ".
There is something that I am not understanding here! Do I have to change both levels at the same time when a localization change requested by the user takes place, so all functions related in both levels (PHP: uasort(), Laravel: Collection->sort(SORT_LOCALE_STRING)) work synchronized? This seems to be a potential source of inconsistencies! (?)
Thanks for the attention.

Related

Problem with configuration of LiveQuery in Parseplatform

Hello i have installed Parse server and parse sdk for php on my Linux Centos Server.
Parse Dashboard: 1.3.3,
Server version: 4.3.0
I'm managing those db's using php code. This parser was installed by someone else. The thing is I'm not sure how to install LiveQuery for my server. I don't know if my version of server is good for this kind of operations. I found some solutions how to enable this feature, but there was something like "index.js" - in my file system it's app.js. Screen of file system
In app.js i added lines:
liveQuery: {
classNames: ["Test"] //List of classes to support for query subscritions
}
I've created class in my db named "Test", then i found solution i need to add
this line
liveQueryUrl: keyLiveQueryUrl, // Required if using LiveQuery
I don't really know how to get this key.
How can i check if LiveQuery works? It will be used by flutter code, but i'd like to check it first in PHP.
My problem has been solved in my other extended topic here.

Symfony messenger can't consume messages

Few weeks ago I set up a Message system with Symfony Messenger and it worked great.
Today I wanted to create new object through message, so I went to my server and type the command to consume message
First I had this result
$ bin/console messenger:consume-messages amqp_notifications
/usr/bin/env: ‘php\r’: No such file or directory
It never happened before with my files, and I never changed the line ending or encoding of my file sin PHPstorm.
I tried to use $ php bin/console messenger:consume-messages amqp_notifications
but then I had this error.
Attempted to load class "AMQPConnection" from the global namespace.
Did you forget a "use" statement?
Pretty weird, because I have have the php-amqp ext installed as you can see on the screenshot of my phpinfo
I didn't change anything in my Message class or Handler.
Also, I tried to call new AMQPConnection() on a random action, just to try, and I didn't get the error.
I'm completely lost with this error this time, as everything is installed.
I use PHP 7.3.1 and symfony Messenger 4.2.2
It seems your second issue was already solved by ccKep on his comment.
The first one is that the specific shebang line #!/usr/bin/env php executes the first php found in the $PATH. So if you already have uninstalled it, which seems the case, or it has a symbolic link to another php version, you can get a wrong result.
Tries to check what is inside the $PATH and replace the PHP path for the correct one. You might get the place running which php.

Connection to Simpro API not working - Tivoka send is failing

I'm having trouble connecting to our Simpro server via the API.
I am using a slightly modified version of the directaccessexample.php as per the Simpro GIT repository here - https://github.com/simPRO-Software/simpro-api-php
My server PHP version is 5.6.32
My composer is loading the below packages:
{
"require": {
"monolog/monolog": "",
"eher/OAuth": "1.0.",
"tivoka/tivoka": "3.1.0",
"psr/log":"*"
}
}
In my attempts to debug, the Client.php script (as provided by the Simpro GIT) appears to fail at specifically the send call from the below lines:
$rpcRequest = new \Tivoka\Client\Request($method, $args);
$this->connection->send($rpcRequest);
I have identified this by outputting to error_log above and below this line - the code appears to die in the function on the send request (and therefore never reaches the second error_log output. There is no error logged that I can see which I find bizarre, it just appears to exit the function.
I am not seeing any other errors in any php error log/apache log/etc, and I've ruled out the issue being the firewall on my server.
I am wondering if this is a problem with versions of PHP or the installed packages from composer - though I have tried a couple of different specific versions without any luck (no change to php version, however).
From the above code, the json_encoded output of $rpcRequest is:
{"id":"7b0911cc-dd67-4032-b810-474e549edecc","method":"CompanySearch","params":["%"],"request":null,"response":null,"result":null,"error":null,"errorMessage":null,"errorData":null,"responseHeaders":null,"responseHeadersRaw":null}
Can anybody assist here? I am pulling my hair out. I'm aware I could attempt to write my own code using different oauth/rpc packages but I am not that advanced with PHP.
Thanks,
Justin.

PHP PhantomJS - "use JonnyW\PhantomJs\Client;" Error?

I've installed PhantomJS and PHP-PhantomJS per the PHP-PhantomJS docs.
Per the PHP-PhantomJS docs, I have the following lines at the top of a php file:
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
When executing $client = Client::getInstance();, I get the error:
'JonnyW\PhantomJs\Client' not found
The installer has placed JonnyW\PhantomJs\Client here:
/Applications/myWebApp/vendor/jonnyw/php-phantomjs/src/JonnyW/PhantomJs/Client.php
The script that contains the "use" command is located here:
/Applications/myWebApp/application/controllers/myPHPscript.php
How can I modify the "use" command so as to locate the required "JonnyW\PhantomJs\Client" file?
I have looked at StackOverflow topics that appear similar but don't seem to provide the answer I need.
Thanks in advance to all for any info.
As noted, I followed the PHP-PhantomJS Docs in installing PhantomJS and PHP-PhantomJS. Per those docs, I used Composer to download and install everything. I'd never used Composer before. I learned that the framework I'm using, CodeIgniter, includes support for Composer. All I had to do was activate Composer support in the CodeIgniter config.php file, via the $config['composer_autoload'] setting.

CakePHP 3.0 not running on other machines

I've developed a small project on a machine, using CakePHP 3.0, and I need it to run on another machine. I've tried to install it on several other machines.
If I run the composer to install the CakePHP 3.0, then I copy my stuff to overwrite it, the project works. I've tried this on two machines and had no problem so far. If I don't run the composer, and just copy the stuff to the target machine, it gives me the following error. I've tried this on 3 machines, and every machine gives me this:
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
I've copied the whole project to this server to test.
I told you this because I thought it has something to do with my problem. The point is that I have to run this on a machine that is not mine, and I can't install composer on it. The /public_html/vendor/cakephp/cakephp/src/I18n/ has files related to internationalization and localization, but my project will never be translated, so a workaround to make the project ignore those files would be enough to solve my problem.
The following code is an excerpt from the (...)/I18n/I18n.php that might be relevant:
<?php
namespace Cake\I18n;
use Aura\Intl\FormatterLocator;
use Aura\Intl\PackageLocator;
use Aura\Intl\TranslatorFactory;
use Cake\I18n\Formatter\IcuFormatter;
use Cake\I18n\Formatter\SprintfFormatter;
use Locale;
class I18n {
// lots of code here
public static function defaultLocale() {
if (static::$_defaultLocale === null) {
static::$_defaultLocale = Locale::getDefault() ?: 'en_US';
// the line above is the Line 229
}
return static::$_defaultLocale;
}
// many code here too
}
I've checked that another file also tries to access this Locale class, but I don't know if there are other files trying to access it as well. Many files from everywhere inside the project tries to access methods from I18n.php. I need it running but I can't figure out how to make it run.
Any help will be greatly appreciated.
As I just found out, prior to CakePHP 3.0, the installation must be done by composer, as stated in the 3.0 migration guide:
CakePHP should be installed with Composer
Since CakePHP can no longer easily be installed via PEAR, or in a shared
directory, those options are no longer supported. Instead you should use
Composer to install CakePHP into your application.
So it won't run on regular free web hosting services.

Categories