Importing Code From Other Probjects

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Importing Code From Other Probjects

Post by Haravikk » Fri Nov 18, 2016 5:28 pm

So I'm finally getting back round to finishing some extensions (previously mods) that I've been putting off, however I've encountered one thing I'm a little unsure about (likely many more to follow though):

Thing is, one of my mods is ideally placed to benefit from code I've done in the past, which I always namespace using reverse URI notation like so: com\haravikk\foo\bar

However, if I want to add this to an extension do I have no choice but to add the \vendor_name\mod part to the beginning? If this is the case it is not going to be pretty as I was hoping to just copy in these classes without having to change them, as there are rather a lot. I suppose I can use some kind of build script to get around this if I have to (i.e- edit namespaces automatically) but it's not something I really want to do, and I fully expect it to go horribly wrong.

Is there any way in PHP to group classes under a namespace even if that's not what they have in the files themselves? e.g- so I can force the classes to be loaded as: haravikk\myawesomemod\com\haravikk\foo\bar?

Does anyone else use outside code a lot? How are you handling it?

User avatar
david63
Registered User
Posts: 16661
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Importing Code From Other Probjects

Post by david63 » Fri Nov 18, 2016 6:48 pm

Not sure what it is that you are saying but having multiple "use" statements is not a problem.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: Importing Code From Other Probjects

Post by Haravikk » Fri Nov 18, 2016 7:21 pm

What I mean is; the code I want to add to my extension is all namespaced as \com\haravikk\blah\blah, but this doesn't meet the requirement that extensions classes be in a namespace beginning with haravikk\mycoolextension, so is there a way for me to add this to my imported code without having to change all of the files?

User avatar
david63
Registered User
Posts: 16661
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Importing Code From Other Probjects

Post by david63 » Fri Nov 18, 2016 9:33 pm

An extension can use any namespace you want - just as long as it can access the files. I am guessing that this will be only for your use and will not be being submitted to the CDB so you are free to do whatever you want.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3936
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Importing Code From Other Probjects

Post by kasimi » Fri Nov 18, 2016 10:05 pm

Note that in case your extension renders templates from within a controller and your controller class doesn't follow namespacing convention you need to manually set your style paths because phpBB will fail to set them up for you: https://github.com/phpbb/phpbb/blob/rel ... #L108-L119

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: Importing Code From Other Probjects

Post by Haravikk » Fri Nov 18, 2016 10:19 pm

david63 wrote:An extension can use any namespace you want - just as long as it can access the files. I am guessing that this will be only for your use and will not be being submitted to the CDB so you are free to do whatever you want.
Why would you guess that? It is not the case; all I'm trying to do is ask if there's an easier way to do this, FFS I don't know why I even bothered now… :?

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4933
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Importing Code From Other Probjects

Post by VSE » Fri Nov 18, 2016 10:57 pm

Code you've done in the past... Sounds like something you would just import into your extension. In which case that part can be namespaced whatever you want. Just the extension itself should be namespaced with your vendor/name to prevent collisions with other extensions..
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

Post Reply

Return to “Extension Writers Discussion”