Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Bugsnag\Configuration;
use Magento\Framework\App\DeploymentConfig\Reader;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Filesystem\DirectoryList;

class Config
{
Expand All @@ -19,6 +20,13 @@ class Config
*/
protected $deploymentConfig;

/**
* Magento's directory list used for fetching the root folder
*
* @var DirectoryList
*/
protected $directoryList;

/**
* Full array of data from env.php
*
Expand All @@ -44,12 +52,18 @@ class Config
* Config constructor
*
* @param Reader $deploymentConfig
* @param DirectoryList $directoryList
*
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Magento\Framework\Exception\RuntimeException
*/
public function __construct(
Reader $deploymentConfig
Reader $deploymentConfig,
DirectoryList $directoryList
)
{
$this->deploymentConfig = $deploymentConfig;
$this->directoryList = $directoryList;
$this->env = $deploymentConfig->load(ConfigFilePool::APP_ENV);
if(isset($this->env['bugsnag'])) {
$this->bugsnagConfig = $this->env['bugsnag'];
Expand All @@ -71,6 +85,12 @@ public function getConfiguration()
if ($releaseStage) {
$this->config->setReleaseStage($releaseStage);
}

$projectRoot = $this->getProjectRoot();
if ($projectRoot) {
$this->config->setProjectRoot($projectRoot);
}

return $this->config;
}
}
Expand Down Expand Up @@ -103,4 +123,24 @@ public function getReleaseStage()
return false;
}

}
/**
* Get the project_root full path from env.php if existent.
*
* This can also be the boolval `true` if it should be resolved using Magento.
*
* @return bool|mixed|string
*/
public function getProjectRoot() {
if (array_key_exists('project_root', $this->bugsnagConfig)) {
$projectRoot = $this->bugsnagConfig['project_root'];
if ($projectRoot === true) {
// The root should be resolved by Magento
return $this->directoryList->getRoot();
} else {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about adding a } if else (is_dir($projectroot)) { check here, but figured this allows more flexibility? Thoughts?

return $projectRoot;
}
}
return false;
}

}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ More information on [Release Stage](https://docs.bugsnag.com/platforms/php/other
...
'release_stage' => 'staging',
...
'project_root' => true || '/path/to/magento',
),

You can set `project_root` to either `true` or the absolute path of the magento installation.
This will cause all paths in Bugsnag to be normalized across deployments and display the errors starting from the magento root.
When the value is set to true it will use Magento's DirectoryList to resolve the root folder. [See documentation on docs.bugsnag.com.](https://docs.bugsnag.com/platforms/php/other/configuration-options/#project-root)

# Support

If you have any issues with this extension, open an issue on [GitHub](https://github.com/Interjar/bugsnag-magento2/issues).
Expand Down