Work with private framework

Hello,

I have developed my own framework to build php applications.
Is it posible to have the original framework at a fixed location, and let new projects make usage of that framework.
I mean not just make a copy of the framework in the project, but always have a real reference to the original framework, so if i extend ore eddit the framework it automaticly is also availible in the projects.

I hope this is possible.

P.S. my framework is compleetly build using namespaces and uses an autoclassloader.

Manny Thanks.

6 comments

Hi there,

Yes, you can, using one of these approaches:

1) Just create a symbolink link from your framework to somewhere inside your project. For example (I'll be using Windows paths here):
Your Framework: D:\Projects\php\MyFramework
Your project root: D:\Projects\php\MyProject
Symbolic link: D:\Projects\php\MyProject\library\MyFramework <--> D:\Projects\php\MyFramework

This way your framework will look like natural part of the project itself (so can be easily deployed/compressed into archive etc) while still physically located elsewhere.

2) Add as Additional Content Root at "Settings | Directories | Add Content Root" -- this way all framework files will be located elsewhere, no links at file system level at all -- it linked "virtually" into a project.

3) If you do not need to edit your Framework files but only reference them (for code completion purposes), you can add it as any other 3rd party library via Settings | PHP | Include paths (it then will be available in Project View panel under "External Libraries" branch)

0

Hello Andriy,

Thaks for your answer.

I use a mac, no windows here :-)

Step 3 sounds the best to me.
The framework will be a project ont its own, so if i need to edit the framework, i will do it at that project level.

P.S. wil the framework files still be included if i start debugging etc etc

Manny thanks,
Wil test this out

0
P.S. wil the framework files still be included if i start debugging etc etc

If you run it on the same computer/OS where PhpStorm is -- then yes (PhpStorm will be able to step into them during debugging). But if it is on remote/virtual computer .. or symbolic links are used, then you will have to provide path mappings at "Settings | PHP | Servers"

If your question was "will PHP itself automatically include my framework files during execution" -- no, you have to use include/require/autoload yourself.

0

Hello Andriy,

In a new project i call from the index.php th FrameWork autoloader like the following.
All request run tru the index.phh by using .htaccass
Will this still work, becouse i use the BASE_PATH als in the FrameWorks auto loader, but the FrameWork is actualy not where the project is?

<?php
// Set the directory path to this main index.php
define('BASE_PATH', dirname(__FILE__));

// Define the AutoClassRequire object
// This object wil automaticly require any new classe to instanciate based on the full namespace path
require(BASE_PATH .'/FlevoHostFrameWork/System/Core/AutoClassRequire.php');
new FlevoHostFrameWork\System\Core\AutoClassRequire();

$controllerLoader = new FlevoHostFrameWork\System\Core\ControllerLoader();
echo $controllerLoader->HtmlOutput();

0

Well ... since those files are NOT in the project .. then how do you expect PHP interpreter itself to pick them up? PhpStorm only helps you during development stage (coding) but not during actual execution (which could be on completely different environment/OS). It's your responsibility to make sure that PHP will load your files.

You have few choices here:
1) Use full-absolute-path or relative-to-your-project-path to load your framework autoloader
2) add path to your framework to include_path config variable in php.ini (or the same but during runtime via set_include_path() ) and let PHP search for it


In your case, I personally would use option #1 from my original reply (symbolic link) as framework files would look like part of the project itself even at file system level.

If you do not want to use it that way -- then use path relative to project itself (option #1 in this post), something like this (depending on your project structure, of course -- but you should have an idea)

require(BASE_PATH . '/../../FlevoHostFrameWork/System/Core/AutoClassRequire.php');
0

Manny thanks for your answers.

I will do some testing to se what will be the best solution for me.
I also now think your option 1 would now be the best and simpel way to get it working.

Greetings,
Eelco

0

Please sign in to leave a comment.