Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未找到laravel 5添加的外部类_Php_Laravel - Fatal编程技术网

Php 未找到laravel 5添加的外部类

Php 未找到laravel 5添加的外部类,php,laravel,Php,Laravel,我有一个php库,它是一组函数,在这里 <?php # Copyright (c) 2010-2011 Arnaud Renevier, Inc, published under the modified BSD # license. namespace App\Gislib; abstract class CustomException extends \Exception { protected $message; public function __toStrin

我有一个php库,它是一组函数,在这里

<?php

# Copyright (c) 2010-2011 Arnaud Renevier, Inc, published under the modified BSD
# license.

namespace App\Gislib;
abstract class CustomException extends \Exception {
    protected $message;
    public function __toString() {
        return get_class($this) . " {$this->message} in {$this->file}({$this->line})\n{$this->getTraceAsString()}";
    }
}

class Unimplemented extends CustomException {
    public function __construct($message) {
        $this->message = "unimplemented $message";
    }
}

class UnimplementedMethod extends Unimplemented {
    public function __construct($method, $class) {
        $this->message = "method {$this->class}::{$this->method}";
    }
}

class InvalidText extends CustomException {
    public function __construct($decoder_name, $text = "") {
        $this->message =  "invalid text for decoder " . $decoder_name . ($text ? (": " . $text) : "");
    }
}

class InvalidFeature extends CustomException {
    public function __construct($decoder_name, $text = "") {
        $this->message =  "invalid feature for decoder $decoder_name" . ($text ? ": $text" : "");
    }
}

abstract class OutOfRangeCoord extends CustomException {
    private $coord;
    public $type;

    public function __construct($coord) {
        $this->message = "invalid {$this->type}: $coord";
    }
}
class OutOfRangeLon extends outOfRangeCoord {
    public $type = "longitude";
}
class OutOfRangeLat extends outOfRangeCoord {
    public $type = "latitude";
}

class UnavailableResource extends CustomException {
    public function __construct($ressource) {
        $this->message = "unavailable ressource: $ressource";
    }
}

interface iDecoder {
    /*
     * @param string $text
     * @return Geometry
     */
    static public function geomFromText($text);
}

abstract class Decoder implements iDecoder {
    static public function geomFromText($text) {
        throw new UnimplementedMethod(__FUNCTION__, get_called_class());
    }
}

interface iGeometry {
    /*
     * @return string
     */
    public function toGeoJSON();

    /*
     * @return string
     */
    public function toKML();

    /*
     * @return string
     */
    public function toWKT();

    /*
     * @param mode: trkseg, rte or wpt
     * @return string
     */
    public function toGPX($mode = null);

    /*
     * @param Geometry $geom
     * @return boolean
     */
    public function equals(Geometry $geom);
}

abstract class Geometry implements iGeometry {
    const name = "";

    public function toGeoJSON() {
        throw new UnimplementedMethod(__FUNCTION__, get_called_class());
    }

    public function toKML() {
        throw new UnimplementedMethod(__FUNCTION__, get_called_class());
    }

    public function toGPX($mode = null) {
        throw new UnimplementedMethod(__FUNCTION__, get_called_class());
    }

    public function toWKT() {
        throw new UnimplementedMethod(__FUNCTION__, get_called_class());
    }

    public function equals(Geometry $geom) {
        throw new UnimplementedMethod(__FUNCTION__, get_called_class());
    }

    public function __toString() {
        return $this->toWKT();
    }
}

class GeoJSON extends Decoder {

    static public function geomFromText($text) {
        $ltext = strtolower($text);
        $obj = json_decode($ltext);
        if (is_null ($obj)) {
            throw new InvalidText(__CLASS__, $text);
        }

        try {
            $geom = static::_geomFromJson($obj);
        } catch(InvalidText $e) {
            throw new InvalidText(__CLASS__, $text);
        } catch(\Exception $e) {
            throw $e;
        }

        return $geom;
    }

    static protected function _geomFromJson($json) {
        if (property_exists ($json, "geometry") and is_object($json->geometry)) {
            return static::_geomFromJson($json->geometry);
        }

        if (!property_exists ($json, "type") or !is_string($json->type)) {
            throw new InvalidText(__CLASS__);
        }

        foreach (array("Point", "MultiPoint", "LineString", "MultiLinestring", "LinearRing",
                       "Polygon", "MultiPolygon", "GeometryCollection") as $json_type) {
            if (strtolower($json_type) == $json->type) {
                $type = $json_type;
                break;
            }
        }

        if (!isset($type)) {
            throw new InvalidText(__CLASS__);
        }

        try {
            $components = call_user_func(array('static', 'parse'.$type), $json);
        } catch(InvalidText $e) {
            throw new InvalidText(__CLASS__);
        } catch(\Exception $e) {
            throw $e;
        }

        $constructor = __NAMESPACE__ . '\\' . $type;
        return new $constructor($components);
    }

   static protected function parsePoint($json) {
        if (!property_exists ($json, "coordinates") or !is_array($json->coordinates)) {
            throw new InvalidText(__CLASS__);
        }
        return $json->coordinates;
    }

    static protected function parseMultiPoint($json) {
        if (!property_exists ($json, "coordinates") or !is_array($json->coordinates)) {
            throw new InvalidText(__CLASS__);
        }
        return array_map(function($coords) {
            return new Point($coords);
        }, $json->coordinates);
    }

    static protected function parseLineString($json) {
        return static::parseMultiPoint($json);
    }

    static protected function parseMultiLineString($json) {
        $components = array();
        if (!property_exists ($json, "coordinates") or !is_array($json->coordinates)) {
            throw new InvalidText(__CLASS__);
        }
        foreach ($json->coordinates as $coordinates) {
            $linecomp = array();
            foreach ($coordinates as $coordinates) {
                $linecomp[] = new Point($coordinates);
            }
            $components[] = new LineString($linecomp);
        }
        return $components;
    }

    static protected function parseLinearRing($json) {
        return static::parseMultiPoint($json);
    }

    static protected function parsePolygon($json) {
        $components = array();
        if (!property_exists ($json, "coordinates") or !is_array($json->coordinates)) {
            throw new InvalidText(__CLASS__);
        }
        foreach ($json->coordinates as $coordinates) {
            $ringcomp = array();
            foreach ($coordinates as $coordinates) {
                $ringcomp[] = new Point($coordinates);
            }
            $components[] = new LinearRing($ringcomp);
        }
        return $components;
    }

    static protected function parseMultiPolygon($json) {
        $components = array();
        if (!property_exists ($json, "coordinates") or !is_array($json->coordinates)) {
            throw new InvalidText(__CLASS__);
        }
        foreach ($json->coordinates as $coordinates) {
            $polycomp = array();
            foreach ($coordinates as $coordinates) {
                $ringcomp = array();
                foreach ($coordinates as $coordinates) {
                    $ringcomp[] = new Point($coordinates);
                }
                $polycomp[] = new LinearRing($ringcomp);
            }
            $components[] = new Polygon($polycomp);
        }
        return $components;
    }

    static protected function parseGeometryCollection($json) {
        if (!property_exists ($json, "geometries") or !is_array($json->geometries)) {
            throw new InvalidText(__CLASS__);
        }
        $components = array();
        foreach ($json->geometries as $geometry) {
            $components[] = static::_geomFromJson($geometry);
        }

        return $components;
    }

}}

每个类或接口都需要位于自己的文件中,文件名与类名匹配

例如,在
app/Gislib/Unimplemented.php
中:

<?php

namespace App\Gislib;

class Unimplemented extends CustomException {
    public function __construct($message) {
        $this->message = "unimplemented $message";
    }
}
<?php

namespace App\Gislib;

interface iDecoder {
    /*
     * @param string $text
     * @return Geometry
     */
    static public function geomFromText($text);
}
这是由于拉威尔遵循了以下标准


如果在分割文件后仍然出现错误,请尝试运行
composer dump

每个类或接口都需要位于自己的文件中,并且文件名与类名匹配

例如,在
app/Gislib/Unimplemented.php
中:

<?php

namespace App\Gislib;

class Unimplemented extends CustomException {
    public function __construct($message) {
        $this->message = "unimplemented $message";
    }
}
<?php

namespace App\Gislib;

interface iDecoder {
    /*
     * @param string $text
     * @return Geometry
     */
    static public function geomFromText($text);
}
这是由于拉威尔遵循了以下标准


如果在分割文件后仍然出现错误,请尝试使用PSR-4自动加载运行
composer dump

,要求类名与文件名匹配。看

但您可以这样修改composer.json文件:

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "files" : [
      "app/Gislib/Gislib.php"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},

添加为“文件”部分,并提供lib的路径。(我认为您必须在那之后进行composer dump autoload。现在它应该可以工作。

对于PSR-4自动加载,需要类名与文件名匹配。请参阅

但您可以这样修改composer.json文件:

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "files" : [
      "app/Gislib/Gislib.php"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},

添加为“文件”部分,并提供lib的路径。(我想你必须在那之后进行composer dump autoload。现在应该可以了。

你在文件顶部添加了名称空间声明吗?@shock\u gone\u wild是的,我刚刚编辑了我的问题,你在文件顶部添加了名称空间声明吗?@shock\u gone\u wild是的,我刚刚编辑了我的问题,你不必为我创建单个文件r每个类。在这种情况下,您可以将其添加到composer.json的自动加载部分的文件数组中。如果您想遵循整个Laravel使用的PSR-4,那么您应该这样做。确定这没有错。只想指出一个替代方法。对于捆绑在一个文件中的外部库,我将使用这种“文件”方法LD认为它不坏(特别是如果文件真的很大)。对于自己的实现,PSR-4当然是必须的。您不必为每个类创建单个文件。在这种情况下,您可以将其添加到composer.json的自动加载部分的文件数组中。如果您想遵循整个Laravel使用的PSR-4,那么您应该这样做。确定没有问题。只是想对于一个在一个文件中捆绑的外部库,这个“文件”方法是一个案例,我认为它不太糟糕(特别是如果文件真的很大)。当然,对于自己的实现,PSR-4是必须的。