我在这篇文章中创建了带有信息的新插件:https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/
我更新了composer.php,在vendor文件夹中我创建了文件,我在后端看到插件phpclasses / evalmath。
在页面上我尝试进行数学运算:
function onStart() {
// instantiate a new EvalMath
$m = new EvalMath;
$m->suppress_errors = true;
// set the value of x
$m->evaluate('x = 3');
var_dump($m->evaluate('y = (x > 5)'));
}
我收到类'EvalMath'未找到的错误类在文件中定义/plugins/phpclasses/evalmath/vendor/phpclasses/evalmath/evalmath.class.php我做错了什么?
文件/plugins/phpclasses/evalmath/composer.json中的
{
"require": {
"phpclasses/evalmath": ">=1.0.0"
},
"repositories": [
{
"type": "composer",
"url": "https:\/\/www.phpclasses.org\/"
},
{
"packagist": false
}
]
}
文件/plugins/phpclasses/evalmath/Plugin.php中的
<?php namespace phpclasses\evalmath;
use App;
use Config;
use System\Classes\PluginBase;
use Illuminate\Foundation\AliasLoader;
/**
*
* Class Plugin */
class Plugin extends PluginBase
{
/**
*
* Returns information about this plugin.
* @return array
*/
public function pluginDetails()
{
return ['name' => 'phpclasses/evalmath',
'description' => 'OctoberCMS plugin for demonstrating the use of Laravel Packages within October plugins',
'author' => 'hhh',
'icon' => 'icon-leaf'
];
}
/**
*
* Runs right before the request route */
public function boot()
{
// Setup required packages $this->bootPackages(); }
/**
*
* Boots (configures and registers) any packages found within this plugin's packages.load configuration value
* @see https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-plugins
* @author Luke Towers octobercms@luketowers.ca
*/
public
function bootPackages()
{ // Get the namespace of the current plugin to use in accessing the Config of the plugin $pluginNamespace = str_replace('\', '.', strtolower(NAMESPACE));
// Instantiate the AliasLoader for any aliases that will be loaded
$aliasLoader = AliasLoader::getInstance();
// Get the packages to boot
$packages = Config::get($pluginNamespace . '::packages');
// Boot each package
foreach ($packages as $name => $options) {
// Setup the configuration for the package, pulling from this plugin's config
if (!empty($options['config']) && !empty($options['config_namespace'])) {
Config::set($options['config_namespace'], $options['config']);
}
// Register any Service Providers for the package
if (!empty($options['providers'])) {
foreach ($options['providers'] as $provider) {
App::register($provider);
}
}
// Register any Aliases for the package
if (!empty($options['aliases'])) {
foreach ($options['aliases'] as $alias => $path) {
$aliasLoader->alias($alias, $path);
}
}
}
}
}
}
文件/plugins/phpclasses/evalmath/classes/config.php中的
<?php
return [
// This contains the Laravel Packages that you want this plugin to utilize listed under their package identifiers
'packages' => [
'phpclasses/evalmath' => [
],
],
];
答案 0 :(得分:0)
如果你没有配置或其他提供者或别名,文件/plugins/phpclasses/evalmath/Plugin.php(bootPackages())
中的大部分代码都不是必需的
如果它是一个laravel包,你可以在启动功能中使用\App::register('\Your\LaravelPackage\ServiceProvider');
使用laravel Provider注册包
并为您的包添加别名
$alias = \Illuminate\Foundation\AliasLoader::getInstance()->alias('YourAlias', '\Your\LaravelPackage\Facade');
如果它不是laravel包,请尝试使用完整的命名空间我认为\EvalMath
如果您使用此包https://www.phpclasses.org/browse/file/11680.html