简体   繁体   中英

PSR-4 namespaces (am I doing it correct?)

I am trying to conform myself to the usage of namespaces within the PSR-4 standard. At this moment I am not totally sure I am using it correct so I am asking some smart guy / girl over here to help me out if it is not :-)!

- third_party
-- Webservices\
-- Webservice.php
--- Requests\
--- Login.php
--- Responses\
--- Login.php

I am using the following namespacing (Composer):

"Webservices\\": "third_party/Webservices"

and for example a requests namespace:

namespace Webservices\Requests\Login;

and for the response namespace:

namespace Webservices\Responses\Login;

and for the Webservice.php file located in the Webservices folder I am using the namespace:

namespace Webservices\Webservice;

I am not totally sure if I am using the last one correct, but I can't think of any other way to make it work propperly.

Any help is appriciated or if it is correct that would also be awsome! :-)

Based on your directory structure this is what your files should look like:

Webservices/Requests/Login.php

namespace Webservices\Requests;

class Login { ... }

Webservices/Responses/Login.php

namespace Webservices\Responses;

class Login { ... }

Webservices\\Webservice.php

namespace Webservices;

class Webservice { ... }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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