This is for Sentry (Open-source error tracking) users.
I have tried some code, but I don't get success. I hope you could look into this.
Thanks to everyone in advance.
I have download the SDK zip and upload it on servers. Well, I have read from some stuff for autoloader and raven_client but still, I don't find autoloder.php.
I am using sentry/sdk:2.0.3
require_once 'sentry-php-master/src/Sdk.php';
Sentry\init(['dsn' => '___DSN___' ]);
throw new Exception("My first Sentry error!");
I am expecting it works and I can trace the errors.
Why aren't you using composer ?
Composer solves a number of problems including dependency resolution for PHP packages, keeping all packages updated and another benefit of using composer is autoloading.
I would suggest the following approach:
composer require sentry/sdk:2.1.0 in your project's root directory.
require_once __DIR__ . '/vendor/autoload.php';
Connect the SDK to Sentry
Sentry\init(['dsn' =>
'https://6cxxx20aa1xxx5axx47xxxb8#sentry.io/18xxx47']);
Lastly, verify your setup by triggering a PHP exception by throwing one as you've already done with throw new Exception("My first Sentry error!");
Docs
Related
I have a set of translations in PHP array. Using Oscarotero's gettext library, I'm getting an error of:
"Cannot redeclare __() (previously declared in
D:\LocaleTesting\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:907)"
when the execution of the code $t->register()
$aTranslation = Translations::fromJsonFile(public_path() . '/locale/'.$sLocale.'/LC_MESSAGES/admin.json');
$oTranslator = new Translator();
$oTranslator->loadTranslations($aTranslation);
$oTranslator->register();
Also, I've search that this error only occur when your Laravel version is 5.4 and above. Any help will do. Thank you! Please Oscarotero/gettext's github for more information about the library.
It seems this is a know issue with the library:
https://github.com/oscarotero/Gettext/issues/180
One way around it is loading the translator functions before laravel helpers are loaded (solution from the issue above):
I'm using the package with a require before vendor/autoload.php on public/index.php and artisan command.
# public/index.php
require __DIR__.'/../vendor/gettext/gettext/src/translator_functions.php';
require __DIR__.'/../vendor/autoload.php';
# artisan
require __DIR__.'/vendor/gettext/gettext/src/translator_functions.php';
require __DIR__.'/vendor/autoload.php';
I need to use jwe in my code. I found a couple of jwe libraries (here and here) that also requires phpseclib to be installed. However, we are not allowed to install composer in our area of work.
How do i reference the jwe and phpseclib libraries without composer? Thanks.
You could use Composer's autoloader without using the full Composer. eg.
<?php
include 'autoload.php';
$loader = new \Composer\Autoload\ClassLoader();
$loader->addPsr4('phpseclib\\', __DIR__ . '/path/to/phpseclib2.0');
$loader->register();
// insert your code here
Where autoload.php is this:
https://raw.githubusercontent.com/composer/composer/master/src/Composer/Autoload/ClassLoader.php
So at that point instead of having to code review the whole of Composer you just code review that one file.
You could also use the auto-loader by PHP-FIG:
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
<?php
include('autoloader.php');
$loader = new \Example\Psr4AutoloaderClass;
$loader->register();
$loader->addNamespace('phpseclib', __DIR__.'/phpseclib');
That said, I do think your companies policies are silly. If you're not going to trust Composer than why would you trust any third-party PHP library? So it's causing you problems with phpseclib today. What other libraries might you want to use in the future that this policy will also cause you problems?
Resolving the issue. My Case:
Before reading the question, my issue was solved due to my development environment. Using CodeKit (an application on MacOS), upon building my code from the source folder, items such as the composer.json and other files did not transfer causing the issues described below. If this does happen to you scout the two folder to look for discrepancies the paste the missing docs from the src to the build folder.
:: QUESTION ::
I am starting to use GCP today and after following the instructions defined here:
composer require google/cloud-storage
then:
putenv("GOOGLE_APPLICATION_CREDENTIALS=/path/to/creds.json");
require __DIR__.'/vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
$myid = "my-project-id";
$storage = new StorageClient([
'projectId'=>$myid
]);
var_dump($storage->buckets());
When running this i get the following error:
Fatal error: Class 'Google\Auth\Cache\MemoryCacheItemPool' not found in /place/to/vendor/google/cloud-core/RequestWrapperTrait.php on line 94
I have no idea how to solve the issue, as i am just getting started with GCP. No idea whether this is a problem with the platform or my code.
File structure appears as follows for the Google Auth:
vendor
google
auth
src
tests
cloud-core
cloud-storage
the /Cache/MemoryCacheItemPool exists inside both the tests and src folder, but the above is referencing it minus the src or tests folder.
I have also ran:
composer update
and uninstalled and reinstalled the package to no effect
Google Cloud Project Link
Where did you find the code that you used and pasted? Because the one present in the official documentation is different.
This portion of code is the one in the tutorial you linked, try to use the client library and post the error logs if get any!
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
$projectId = 'YOUR_PROJECT_ID';
$storage = new StorageClient(['projectId' => $projectId]);
$bucketName = 'my-new-bucket';
$bucket = $storage->createBucket($bucketName);
echo 'Bucket ' . $bucket->name() . ' created.';
Remember that bucket name should be unique and therefore I would advice you to test it with a long complex name to avoid to hit already used names, and always test the result of the operation.
UPDATE
I tested also your code and it is working as well, therefore I believe that is an error in the setup of the environment.
Did you get any error while running the composer require google/cloud-storage? Because the class that is missing Google\Auth\Cache\MemoryCacheItemPool is part of Psr that is installed by the composer
[...]
Installing psr/cache (1.0.1)
Loading from cache
[...]
UPDATE2
Matthew M found the error in its configuration and posted:
Finally resolved the issue. I'm using CodeKit in my working
environment and it looks like it is changing something when it
compiles. Ran an uncompiled version and it's working fine.
I'm developping a package for Laravel 5.3+ ( My tests where developped in Laravel 5.3)
I have installed Laravel 5.4, downloaded laravel/browser-kit-testing, and follow upgrade guide.
Now, when I run my tests, I get :
PHP Fatal error: Trait 'Illuminate\Foundation\Testing\DatabaseTransactions' not found
I don't really understand why, because file exists.
In my BrowserKitTestCase.php, I have a reference to
$app = require __DIR__.'/../bootstrap/app.php';
But as I am in my package development folder, I don't think app.php exists, it might be the issue, but can't find out how to fix it...
I tried to change it to:
$app = require __DIR__.'/../../../../bootstrap/app.php';
where app can be found ( I am in /package/author/plugin/tests/ ) but it error remains the same...
Any idea what's happening???
Monolog : http://github.com/Seldaek/monolog
Symfony Class Loader : https://github.com/symfony/ClassLoader
As per the usage instructions on the Monolog site, I'm trying to load the class loader to load monolog in my php project. I cant get 'Composer' installed on my machine (firewall problems from my work machine), so I'm trying to follow the instructions on monolog and symfony sites but I'm having issues.
Here is my SAMPLE of my directory structure with my php code :
myProj/
--ClassLoader/ (symfony)
----UniversalClassLoader.php
--Monolog/
----Formatter/
----Handler/
----Processor/
----Logger.php
--myPhpFile.php
And here is my php code to attempt to 'require' monolog
require_once(realpath('ClassLoader/UniversalClassLoader.php'));
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->register();
$loader->registerNamespace('Monolog', realpath('Monolog'));
require_once(realpath('Monolog\Logger.php')); //exception generated here! :-(
and here is the php exception I'm getting inside the Monolog\Logger.php as soon as it attempts to 'require' monolog
Interface 'Psr\Log\LoggerInterface' not found
but I cant even FIND anything that looks like a 'psr\log' namespace in the monolog code. What bits am I missing?
Psr\Log is a dependency of monolog, if you are not using Composer you'll have to track down all dependencies and it's probably not going to be fun (though for monolog there is only the psr-log package). If you really want you can find it at https://github.com/php-fig/log - but you could also try to download composer via your browser, just grab https://getcomposer.org/composer.phar