Parse error when run illuminate/database/capsule with bootEloquent() in PHP - php

I'm trying to make a mysql connection within a php environment using Slim and the package illuminate/database. Following the documentation I have created a new $capsule instance, I have passed the array with connection data through the addConnection method and then I have run bootEloquent() method:
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => $app->config->get('db.driver'),
'host' => $app->config->get('db.host'),
'database' => $app->config->get('db.database'),
'username' => $app->config->get('db.username'),
'password' => $app->config->get('db.password'),
'charset' => $app->config->get('db.charset'),
'collation' => $app->config->get('db.collation'),
'prefix' => $app->config->get('db.prefix')
]);
#here the output seems correct...
#var_dump($capsule);
$capsule->bootEloquent();
?>
Unfortunately when I run bootEloquent() it goes through an error:
Parse error: parse error in
/Sites/auth/vendor/illuminate/database/Eloquent/Model.php
on line 597
The problem seems related to the Eloquent Model.
I have already tried to update the composer.json file with different versions. I have also installed again each package, but the parse error still remains.
Currently the project is running on: PHP Version 5.6.30.
My current composer json file with all dependencies
{
"autoload": {
"psr-4": {
"Business\\": "app/Business"
}
},
"require": {
"slim/slim": "~2.0",
"slim/views": "0.1.*",
"twig/twig": "~1.0",
"phpmailer/phpmailer": "~5.2",
"hassankhan/config": "0.8.*",
"illuminate/database": "~5.0",
"alexgarrett/violin": "2.*",
"ircmaxell/random-lib": "~1.1"
}
}
Can someone explain me why I'm getting this strange bad situation?
Thanks in advance.

Have a look at your composer.lock to see which version of illuminate/database got installed. The later ones are not compatible with PHP 5.6.30, but require PHP 7. You could try to enforce that version constraint through "illuminate/database": "~5.4.0"

Related

Laravel shopping cart (5.8)

I'm using eclipse PDT, with CodeMix, Terminal+, Composer, and symphony. I created a Laravel project and in my composer.json I have the following dependencies:
"require" : {
"php": "^7.1.3",
"cyvelnet/laravel5-fractal": "^2.3",
"darryldecode/cart": "~4.0",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"intervention/image": "dev-master",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"league/fractal": "^0.18.0",
"ssheduardo/redsys-laravel": "~1.3.0"
},
I also added in my app.php both the service provider
'providers' => [
#Lots of other providers here
Darryldecode\Cart\CartServiceProvider::class,
],
and the facade alias
'aliases' => [
#lots of other aliases
'Cart' => Darryldecode\Cart\Facades\CartFacade::class
],
I even published the provider php artisan vendor:publish --provider="Darryldecode\Cart\CartServiceProvider" --tag="config"
But somehow whenever I try to include the thing in any of my files either with use \Cart;, use \Darryldecode\Cart\Facades\CartFacade; or use \Darryldecode\Cart\Cart; it gives me a
The import whichever one I'm using cannot be resolved
Already tried clearing the cache, closing, and opening eclipse, deleting the project from the workspace and starting it again, uninstalling and reinstalling the cart and I don't know what else to do. Also tried Gloudemans instead and it gives me the same error.
Just using
'Cart' => Darryldecode\Cart\Cart::class,
instead of
'Cart' => Darryldecode\Cart\Facades\CartFacade::class
I solved it by manually adding the vendor folder to the builpath, foir some strange reason composer wasn't adding it.

Deploying a Symfony app - ClassNotFoundException Error

I am learning the Symfony framework and trying to deploy a simple boilerplate app I put together to Heroku using Git.
The deployment fails due to the following fatal error:
Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "WebServerBundle" from namespace "Symfony\Bundle\WebServerBundle
Did you forget a "use" statement for another namespace? in /tmp/build_cbeb92af6c9ee04b07e1f85618211649/src/Kernel.php:32
Kernel.php
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class Kernel extends BaseKernel {
use MicroKernelTrait;
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function getCacheDir(){
return $this->getProjectDir().'/var/cache/'.$this->environment;
}
public function getLogDir(){
return $this->getProjectDir().'/var/log';
}
public function registerBundles(){
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader){
$container->setParameter('container.autowiring.strict_mode', true);
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
if (is_dir($confDir.'/packages/'.$this->environment)) {
$loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
}
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
}
protected function configureRoutes(RouteCollectionBuilder $routes){
$confDir = $this->getProjectDir().'/config';
if (is_dir($confDir.'/routes/')) {
$routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
}
if (is_dir($confDir.'/routes/'.$this->environment)) {
$routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
}
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
}
}
What Ive done so far:
install the dotenv bundle (composer require symfony/dotenv)
run composer dump-autoload
set the production environment variable via the heroku CLI as per this article (heroku config:set SYMFONY_ENV=prod)
Some things Ive learned/have noticed:
According to the README file for WebServerBundle:
WebServerBundle provides commands for running applications using the PHP
built-in web server. It simplifies your local development setup because you
don't have to configure a proper web server such as Apache or Nginx to run your
application.
.. that is, WebServerBundle is a development dependency - yet it is being included in production.
WebServerBundle is also being included in the composer.lock file under autoload
"autoload": {
"psr-4": {
"Symfony\\Bundle\\WebServerBundle\\": ""
},
...
},
My bundles.php file includes WebServerBundle for dev
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
];
I have a .env file and a .env.dist file - Im assuming the .env.dist file is for production? They both have the same contents:
APP_ENV=dev
APP_SECRET=0473d15a4ce2723619d2e8b0405186d3
Im pretty new to symfony and do not really understand how a production environment is instantiated other than that the dotenv bundle reads the .env file and sets the environment variables.
Any help and clarity on all of this would be appreciated.
Edit: here is my composer.json file
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "^4.0",
"symfony/console": "^4.0",
"symfony/dotenv": "^4.0",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4#dev",
"symfony/twig-bundle": "^4.0",
"symfony/yaml": "^4.0"
},
"require-dev": {
"symfony/profiler-pack": "^1.0",
"symfony/web-server-bundle": "^4.0"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-apcu": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"id": "01C1BVQJ19BG3WAS3299PDHH9P",
"allow-contrib": false
}
}
}
I'm not sure about the command you are using, (I use git)
heroku config:set SYMFONY_ENV=prod
But if your .env file has
APP_ENV=dev
That is explictly setting the environment to dev, so it is trying to load dev dependencies (proven by your error) which don't get pushed to the server(read the article you provided).
You need the .env file that is on the server to have APP_ENV=prod
The .env is for the specific machine, it is ignored by git, while .env.dist is tracked. So edit the .env.dist and commit it, then once it is on the server just rename it .env then I would run composer install or composer update on the server which will update dependencies and clear the cache. Then refresh your browser.
The answer likely depends on how you deploy your app and I assume you will install only production dependencies in your deployment, i.e. you run composer with --no-dev as you should. This means that none of the dev dependencies, which very likely includes the webserver-bundle as this is not needed in production where you use a real webserver like apache or nginx, are installed.
What it boils down to is either your code requiring this dev dependency which is not installed or your webserver is trying to run your app in the wrong APP_ENV.
If it's the latter you should check your webserver config if you set the appropriate environment variables (APP_ENV & APP_DEBUG at the very least, probably also the DATABASE_URL). In apache you have to use SetEnv APP_ENV prod and in nginx you use fastcgi_param APP_ENV prod.
edit: I just read that you use composer, so dev dependencies are definitely not installed as is mentioned in the Getting Started Guide: https://devcenter.heroku.com/articles/php-support#build-behavior
So you can't use the dev environment for Symfony or you have to reinstall the dev-dependencies as regular dependencies using composer (which is absolutely not recommended).

Geolocation package with laravel: Midnite81\Geolocation\GeoLocationServiceProvider' not found

I want to use the following package for geolocation with laravel.
https://github.com/midnite81/geolocation
I have done everything they wrote in their documentation but find an error
Midnite81\Geolocation\GeoLocationServiceProvider' not found
i am unable to solve this problem. Can't understand what's wrong. What i did, at first, write "midnite81/geolocation": "1.*" in the composer.json file.
"require": {
"php": ">=7.0.0",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"midnite81/geolocation": "1.*"
},
After that run composer update. Then run composer dump-autoload -o. Then in the config/app.php file, put the following part in providers and aliases array.
'providers' => [
Midnite81\Geolocation\GeoLocationServiceProvider::class
];
'aliases' => [
'GeoLocation' => Midnite81\GeoLocation\Facades\GeoLocation::class,
];
then run the following command.
php artisan vendor:publish --provider="Midnite81\GeoLocation\GeoLocationServiceProvider"
Then got the error, Midnite81\Geolocation\GeoLocationServiceProvider' not found
Can't figure out what's wrong in it.
I verified and confirm the problem.
The problem is:
Midnite81\Geolocation\GeoLocationServiceProvider::class
You should change this into
Midnite81\GeoLocation\GeoLocationServiceProvider::class
Notice the difference Geolocation vs GeoLocation. It seems there is error in readme for this package on Github
I've already sent Pull request https://github.com/midnite81/geolocation/pull/2 to fix readme for this package

Mediawiki extensions, will not read my i18n file

As far as i'm aware, the only steps required in order to create a internationalized extension is to create a i18n file like the following:
//SemanticHighcharts.i18n.php
$messages = array();
$messages['en'] = array(
'semantichighcharts-desc' => 'A SMW result format displaying data with the help of highcharts
);
and then reference this file with the global variable wgExtensionMessageFiles
//SemanticHighcharts.php
global $wgExtensionMessagesFiles, $wgExtensionCredits;
$wgExtensionCredits['semantic'][] = array(
'path' => __FILE__,
'name' => 'SemanticHighcharts',
'version' => '0.0.1',
'url' => 'https://www.mediawiki.org/wiki/Extension:SemanticHighcharts',
'descriptionmsg' => 'semantichighcharts-desc'
);
//i18n
$wgExtensionMessagesFiles['SemanticHighcharts'] = dirname(__FILE__) . '/SemanticHighcharts.i18n.php';
This should cause the descriptionmsg in wgExtensionCredits to be internationalized when displayed on Special:Version.
However this is not the case... In fact, no message key from the i18n file is being read!
How can i debug this issue? I've tried to debug callstack when doing a wfMessage() call without any great success.
Any help is appreciated. I'm running the latest version of mediawiki from git. And all extensions have been installed with composer.
//composer.json
{
"require": {
"php": ">=5.3.2",
"mediawiki/side-bar-menu": "dev-master",
"mediawiki/semantic-highcharts": "dev-master",
"mediawiki/semantic-result-formats": "dev-master"
},
"suggest": {
"ext-fileinfo": "*",
"ext-mbstring": "*",
"ext-wikidiff2": "*",
"ext-apc": "*"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/netbrain/SemanticHighcharts"
}
]
}
Typical, after struggling with this issue for quite some time. Right after posting this question I tried to remove all other extensions from composer.json, and did a composer update. Which magically fixed my issue.
I'm suspecting that there might be a conflicting extension or maybe it was just something wrong with the composer autoloading mechanism.
Ill try to look into it further.
It seems that composer was the culprit, after re-adding the extensions previously removed, it still worked. So i can only guess that there is some quirk in composers dependency management.

Zend2 install ZendOauth module with composer

I'm totally new to zend2 and would like to install the zendframework/zendoauth module.
I added the module to composer.json and installed it properly with "composer install"
Contents of my composer.json
{
"name": "my_project_name",
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": ">2.2.0rc1",
"doctrine/doctrine-module": "*",
"doctrine/doctrine-orm-module": "*",
"zendframework/zendoauth": "2.0.*",
}
}
This downloaded the module into vendor/zendframework/zendoauth.
I edited config/application.config and added 'ZendOauth'.
Contents of my config/application.config.php
<?php
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'Application',
'ZendOAuth'
),
...
Now when i try to access my website i get an error:
Fatal error:
Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException'
with message 'Module (ZendOAuth) could not be initialized.'
My question is: Is there anything i missed?!
Thanks in advance!
ZendOAuth isn't a module, it's a library, which is why you're getting an error message when you add it to the list of modules. You just use the classes it supplies in your own application.
Unfortunately, there doesn't appear to be any documentation for it at the moment, but to get an idea of usage, maybe take a look at the unit tests https://github.com/zendframework/ZendOAuth/tree/master/tests/ZendOAuth

Categories