PHP如何在Class文件中包含composer autoload

时间:2017-06-16 02:50:35

标签: php composer-php autoloader

我很难在类文件中包含composer autoload,它不能在map(m => (m.toByteArray.length -> new BytesWritable(m.toByteArray))).saveAsSequenceFile(path, Some(classOf[SnappyCodec]))

上工作
// Text Detect
func textDetect(dectect_image:UIImage, display_image_view:UIImageView)->UIImage{
    let handler:VNImageRequestHandler = VNImageRequestHandler.init(cgImage: (dectect_image.cgImage)!)
    var result_img:UIImage = UIImage.init();

    let request:VNDetectTextRectanglesRequest = VNDetectTextRectanglesRequest.init(completionHandler: { (request, error) in
        if( (error) != nil){
            print("Got Error In Run Text Dectect Request");

        }else{
            result_img = self.drawRectangleForTextDectect(image: dectect_image,results: request.results as! Array<VNTextObservation>)
        }
    })
    request.reportCharacterBoxes = true
    do {
        try handler.perform([request])
        return result_img;
    } catch {
        return result_img;
    }
}

func drawRectangleForTextDectect(image: UIImage, results:Array<VNTextObservation>) -> UIImage {
    let renderer = UIGraphicsImageRenderer(size: image.size)
    var t:CGAffineTransform = CGAffineTransform.identity;
    t = t.scaledBy( x: image.size.width, y: -image.size.height);
    t = t.translatedBy(x: 0, y: -1 );

    let img = renderer.image { ctx in
        for item in results {
            let TextObservation:VNTextObservation = item
            ctx.cgContext.setFillColor(UIColor.clear.cgColor)
            ctx.cgContext.setStrokeColor(UIColor.green.cgColor)
            ctx.cgContext.setLineWidth(1)
            ctx.cgContext.addRect(item.boundingBox.applying(t))
            ctx.cgContext.drawPath(using: .fillStroke)

            for item_2 in TextObservation.characterBoxes!{
                let RectangleObservation:VNRectangleObservation = item_2
                ctx.cgContext.setFillColor(UIColor.clear.cgColor)
                ctx.cgContext.setStrokeColor(UIColor.red.cgColor)
                ctx.cgContext.setLineWidth(1)
                ctx.cgContext.addRect(RectangleObservation.boundingBox.applying(t))
                ctx.cgContext.drawPath(using: .fillStroke)
            }
        }

    }
    return img
}

在类中加载多个包含文件的正确方法是什么?

2 个答案:

答案 0 :(得分:1)

如果您(正确)使用作曲家,则需要添加供应商自动加载文件。然后通过composer vendor library添加其他依赖项或添加自定义路径(composer为您完成其余的工作)。

例如,更简单:

  1. 从一个空目录开始
  2. 启动命令:
  3.   

    php composer.phar init

    1. 使用命令(由packagist网站建议)在composer.json文件中添加库的依赖关系(如果您不在init进程中添加它)
    2.   

      composer需要phpmailer / phpmailer

      1. 然后你的班级应该是:

        require_once('../vendor/autoload.php');
        
        class Test {
        
        function X()
        { ... }
        
        }
        
      2. 希望这个帮助

答案 1 :(得分:-1)

我想你想要这样的东西

class Loader
{
    public function __construct()
    {
        require_once('phpmailer/PHPMailerAutoload.php');
        require_once('../vendor/autoload.php');
    }
}

$loader = new Loader();

只需添加一些功能

告诉我这是否对你有帮助... goodluck