在验证Lib

时间:2016-08-15 07:12:38

标签: php composer-php autoload respect-validation

我是作曲家的新手,但我可以从cmd获得vendorcomposer.lockcomposer.json,然后将其粘贴到没有Validation_Master文件夹的项目中。 我的项目路径:C:\wamp64\www\php Projects\project 1\(here there are test.php and vendor, composer.lock and composer.json) Validation_Master文件夹路径:C:\wamp64\www\php Projects\Validation_Master 我的代码是:

<?php
    require "vendor/autoload.php";
    use Respect\Validation\Validator as v;
    $number = 123;
    v::numeric()->validate($number);
?>

但上面的代码给出了以下错误:

  

致命错误:未找到类'Respect \ Validation \ Validator'   C:\ wamp64 \ www \ php Projects \ project 1 \ test.php

我做了什么?!!? 将Validation_Master文件夹复制到test.php的路径==&gt; (失败)
将供应商文件夹复制到Validation_Master文件夹的路径并从那里需要==&gt; (失败)
大量操作命名空间并将命名空间Respect \ Validation添加到代码==&gt; (失败)
有什么问题 ???? 我如何使用尊重验证库?????请基本回答我(我以前读过文档但没有帮助)
vendor folder image
composer.json代码:

{
    "name": "respect/validation",
    "description": "The most awesome validation engine ever created for PHP",
    "keywords": ["respect", "validation", "validator"],
    "type": "library",
    "homepage": "http://respect.github.io/Validation/",
    "license": "BSD Style",
    "authors": [
        {
            "name": "Respect/Validation Contributors",
            "homepage": "https://github.com/Respect/Validation/graphs/contributors"
        }
    ],
    "require": {
        "php": ">=5.6"
    },
    "require-dev": {
        "egulias/email-validator": "~1.2",
        "malkusch/bav": "~1.0",
        "mikey179/vfsStream": "^1.5",
        "phpunit/phpunit": "~5.3",
        "symfony/validator": "~2.6.9",
        "zendframework/zend-validator": "~2.3"
    },
    "suggest": {
        "ext-bcmath": "Arbitrary Precision Mathematics",
        "ext-mbstring": "Multibyte String Functions",
        "egulias/email-validator": "Strict (RFC compliant) email validation",
        "malkusch/bav": "German bank account validation",
        "symfony/validator": "Use Symfony validator through Respect\\Validation",
        "zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation",
        "fabpot/php-cs-fixer": "Fix PSR2 and other coding style issues"
    },
    "autoload": {
        "psr-4": {
            "Respect\\Validation\\": "library/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Respect\\Validation\\": "tests/library/"
        }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "2.0-dev"
        }
    },
    "scripts": {
        "test": "./vendor/bin/phpunit"
    }
}

autoload.php代码:

<?php
require_once  __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit46e0d859a60be6f2acf30ed92a2228ad::getLoader();

我很感激和抱歉,我写了很多

更新:我的问题就像这篇帖子:Why my autoload.php of composer doesn't work?,但它没有帮助
我还在cmd ==&gt;中运行composer dump-autoload (失败)

1 个答案:

答案 0 :(得分:0)

在我看来,你复制了respect/validation库的composer.json,并尝试将它用作项目的composer.json。这是一种完全错误的方法。

将此用作项目composer.json:

{
  "require": {
    "respect/validation": "^1.0"
  }
}

然后:

  • 运行composer install
  • 再次运行您的脚本。