简体   繁体   English

我的作曲家项目的类不会加载

[英]My composer project's class won't load

I have a Packagist package for composer, lwilson/onepage , with one PHP file.我有一个用于作曲家的 Packagist 包, lwilson/onepage ,带有一个 PHP 文件。 The file has one class, which contains one function.该文件有一个类,其中包含一个函数。 I have installed the package on my Web server, and I have a PHP file which is supposed to use it.我已经在我的 Web 服务器上安装了该软件包,并且我有一个应该使用它的 PHP 文件。 I know that the composer autoloader is included properly, since I could use other composer libraries installed on the server.我知道 Composer 自动加载器已正确包含在内,因为我可以使用服务器上安装的其他 Composer 库。 I get the following result:我得到以下结果:

Fatal error: Class 'OnePage\OnePage' not found in /home/photox952/public_html/onepage/test_onepage.php on line 6

test_onpepage.php (the file that uses the class): test_onpepage.php (使用该类的文件):

 <?php require '../../vendor/autoload.php'; use OnePage\\OnePage; file_put_contents("index.php",OnePage::OnePage(json_decode(file_get_contents("cfg.json")),__DIR__)); ?>

compiler.php (the file in the package): compiler.php (包中的文件):

 <?php namespace OnePage; // This is licenced under the GNU GENERAL PUBLIC LICENSE. More info at: https://github.com/LeoWilson-XnD/lwilson_onepage/blob/master/LICENSE class OnePage{ public static function OnePage($cfg,$dir){ $tmplt_u = "<?php if(\\$_REQUEST['type']==\\"{TYPE}\\"&&\\$_REQUEST['src']==\\"{SRC}\\"){header(\\"Content-Type: {CT}\\"); ?>{DATA}<?php } ?>"; $tmplt_c = "<?php if(\\$_REQUEST['all']==\\"{TYPE}\\"){header(\\"Content-Type: {CT}\\"); ?>{DATA}<?php } ?>"; $res = "<?php /* This code is generated by the OnePage tool. Find out more here: https://github.com/LeoWilson-XnD/lwilson_onepage */ ?>"; $dir.=$cfg['dir']; if($cfg['v']==1){ foreach($cfg['unique'] as $ka => $va){ foreach($cfg[$ka] as $kb => $vb){ $u = $tmplt_u; $u=str_replace("{TYPE}",explode("/",$ka)[1],$u);$u=str_replace("{SRC}",$kb,$u);$u=str_replace("{CT}",$ka,$u);$u=str_replace("{DATA}",file_get_contents($dir.$vb),$u); $res.=$u; } } foreach($cfg['combine'] as $ka => $va){ $ds = ""; foreach($cfg[$ka] as $kb => $vb){ $ds.=file_get_contents($dir.$vb); } $u = $tmplt_c; $u=str_replace("{TYPE}",explode("/",$ka)[1],$u);$u=str_replace("{CT}",$ka,$u);$u=str_replace("{DATA}",file_get_contents($dir.$vb),$u); $res.=$u; } foreach($cfg['links'] as $key => $val){ $res = str_replace($val,$key,$res); } } return $res; } } ?>

composer.json (the package's composer.json file): composer.json (包的composer.json文件):

 { "name": "lwilson/onepage", "description": "This allows users to compile websites easily into one PHP file.", "authors": [ { "name": "Leo Wilson", "email": "lwilson@xlww.net", "homepage": "https://xlww.net/", "role": "Developer" } ], "minimum-stability": "stable", "version": "v1.0.0", "homepage": "https://github.com/LeoWilson-XnD/lwilson_onepage", "licence":"GPL-3.0", "require": { "php": ">=5.3.0" }, "autoload": { "psr-4": { "": "/" } } }

I apologize in advance if I'm missing something obvious.如果我遗漏了一些明显的东西,我提前道歉。

I think you set the autoload wrong in composer.我认为您在作曲家中设置了错误的自动加载。 Try to create a folder named OnePage and put the file with the class in it.尝试创建一个名为OnePage的文件夹并将OnePage类的文件放入其中。 It must be named OnePage.php它必须命名为OnePage.php

Then set autoload like this然后像这样设置自动加载

  "autoload": {
    "psr-4": {
      "OnePage\\": "OnePage"
    }
  }

then run composer update from the shell.然后从 shell 运行composer update Then try running your php file again.然后再次尝试运行您的 php 文件。

The OnePage.php file should be in folder /home/photox952/public_html/onepage/OnePage OnePage.php文件应该在文件夹/home/photox952/public_html/onepage/OnePage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM