Phpdocumentor looks for custom templates in vendor directory - php

I need to create custom template for PhpDocumentor. The problem is that paths defined in the template.xml, even when specified as absolute ones, are not resolved correctly. PhpDocumentor looks for them in the vendor directory.
<template>
<author>Code Mine</author>
<email>office#code-mine.com</email>
<description>Template for Confluence API</description>
<version>1.0.0</version>
<transformations>
<transformation writer="twig" source="./index.html.twig" artifact="index.html"/>
<transformation query="indexes.namespaces" writer="twig" source="./namespace.html.twig" />
<transformation query="indexes.classes" writer="twig" source="./class.html.twig" />
</transformations>
</template>
Despite fact that twig templates are located in path to which xml refers, I'm getting error that files don't exist.
EDIT:
I have also tried with setting up all configuration details in phpdoc.xml in hope that paths will be considered relative to configuration file but with no luck.

If you specify a custom template with --template="..." it will (for some strange reason) copy that entire template into the vendor folder together with the original templates, and therefore the path structure in template.xml needs to remain the same. You only need to change eg. templates/clean/ to templates/yourtemplatename/.
I have an issue with caching though. I can't get it to reread my template every time. It has cached it somewhere and I can't for the life of me figure out where. Documentation is really bad and source is worse.
Update:
Finally figured out that it cached my template in the temp folder of my computer. For Windows eg.: c:\Users\<username>\AppData\Local\Temp\phpdoc-twig-cache\. So I just delete that entire folder.

Correct me if I'm wrong but it seems like you can just pass a file path on the CLI
https://www.phpdoc.org/docs/latest/getting-started/changing-the-look-and-feel.html
Using a custom template When you have a company or project-branded template you can also use that with phpDocumentor by providing the location of your template’s folder:
$ phpdoc -d "./src" -t "./docs/api" --template="data/templates/my_template"
you may need to back out of the vendors directory with a few ..'s like so
--template="../../data/templates/my_template"
or pass an absolute path
--template="/var/scratch/foo/data/templates/my_template"

Related

how i create relative path alway begining root

I create my web app with php follow mvc model.
When I set path css,img,js,... i use <link rel="stylesheet" href="./public/css/style.css">
in default controller I got css for my page. But when I call action like http://localhost/assignment/controller/action i lost my css. relative path become http://localhost/assignment/controller/action/public/css/style.css or http://localhost/assignment/controller/action/param/public/css/style.css.
Sounds like you might have a configuration or bundler issue. The quickest - not best fix - for developing would be to move your css file to where the public folder is located. You need to find the root folder where that link is calling from and link there.
If you are using a bundler or transpiler, you might need to look in the configs for what is being bundled.
Also make sure to follow this format for local files.
The right way of setting <a href=""> when it's a local file

Translate text in config folder cakephp 3

I'm trying to internationalize a CakePHP 3 application using cake i18n extract. All the texts coming from src folder are translated fine, but I have some text that I put inside config/bootstrap.php but those don't get translated even though I placed them inside the double underscore function __('My text') and I also generated the translation files in src/Locale folder (the same way I did for the other texts that work.
Any idea why my texts in config/bootstrap.php won't get translated?
Thanks in advance for any help
They do not show up because by default the extract task only looks in the src folder. When running the task it will ask you from what paths to extract, and it should only list the src folder by default.
You can either add your custom paths interactively in the shell when it asks you for the folders that should be looked up, or you can use the paths option to define them in beforehand, like:
bin/cake i18n extract --paths /var/www/app/config,/var/www/app/src
When doing so may also want to use the output option to specify the output path, as the task will use the first path as the root for output, ie with the above paths it would put the files in config/Locale instead of src/Locale. Alternatively you can switch the paths, but then the messages from the config folder files would appear at the bottom of the .pot file.
See also
Cookbook > Console Tools, Shells & Tasks > I18N Shell > Generating POT Files > Extracting from multiple folders at once
It depends on where you set the application locale with I18n::setLocale(). Your application using App.defaultLocale setting to determinate wich language sould be shown.
If you change your language in your controller, your configuration files already loaded so this will not effect on these files just on those files what will be loaded after your setLocale.
Try to change your language before translatable files loaded, or load translate configuration files in controller after changeing the appLocale.

How to move Joomla's configuration.php file above the root folder in a web host?

I have installed a security solution in my Joomla website,and it's suggest that to put the configuration.php file above the Public_html Folder,how could it be possible?
how to tell the CMS to recognize the new location?
is the solution would be valid in all versions of the Joomla CMS? ,if it's not,so please
write:
1st:Joomla 2.5 Solution.
2nd:Joomla 3 Solution.
you would need to modify the defines.php file located in the includes folder.
Specifically this line:
define('JPATH_CONFIGURATION', JPATH_ROOT);
And change JPATH_ROOT to the correct path.
But the problem with this is that you are modifying a core file so if an update changes the defines.php file it will overwrite your changes and will break your setup. You will need to reedit the file.
Also the JPATH_CONFIGURATION constant may be used for other things within the CMS that are not specifically trying to get the configuration.php file so make sure to check that it will not adversely affect other parts of the cms before doing this in production.
Alternatively you can change the frameworks.php file (also in the includes folder) directly to change from where the configuration is loaded from
ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();
Just change the require_once line to the correct path.
Again since this is a core file it could be changed by an update. But this may also affect other parts if the config file is loaded manually in components or other parts of the cms.
Simply answer is don't do it. This would mean you would have to do what #Patrick has suggest which is correct and will work, however it means editing a core Joomla file. This is not a good idea as in your case, if you ever update Joomla, you will have to perform this change every time and it you forget (which is likely), your site will stop working completely.
I would strongly suggest you find a different "security solution" which does not involve having to modify any core Joomla files.
If you could define what you mean by "security solution", then maybe an alternative could be provided for you
I didn't dig for 'since when this has been implemented', But it can be done without changing the core.
Joomla looks for a defines.php in the root and if its present, imports it. And then if it finds a constant named _JDEFINES defined, it doesn't load the original file, effectively overriding it completely.
So, If you wish to override the defines its pretty easy and all you have to do is copy the contents of the defines.php file from under the webroot/includes/ path and paste it inside the one we created in the webroot. And you can change the following constant as per your taste.
define('JPATH_CONFIGURATION', JPATH_ROOT."/my/supersecret/directory");
Now there is one more thing left to be done and then we are good to go :)
You have to prepend the following lines to the top of our override file (the defines.php in the webroot).
define('JPATH_BASE', __DIR__);
define('_JDEFINES', 1);
This constant conveys to the framework that the defines have been overridden and to use the new file accordingly (Last time I checked, this flag/constant is checked at around 10 different places all over the framework eg. here, so its important)
Also I have seen this feature available with Joomla v2.5.0 and v3.8.8 as per your requirements in the question.
Edit: Remember you have to repeat the same procedure for administrator folder too if you want admin panel to work, and remember that administrator has its own /includes/defines.php

CakePHP Shared core for multiple apps

On my local setup I have a load of different CakePHP websites. I'm using a Mac so the folder structure is something like ~/Users/cameron/Sites/sample-website and then within each of these websites I will have the typical Cake folder and App folder.
What I would like to do is have just a core cake folder and then have ALL the sites pull from that one cake core so I don't have the same stuff several times over. I have been reading some tutorials on the web: http://rickguyer.com/cakephp-one-core-many-apps/
So I have my cake folder here: ~/Users/cameron/Sites/cake-1.3/ and then my site here: ~/Users/cameron/Sites/sample-site/ and in this folder I have the usual app folder and htaccess to tell it where to find webroot etc.
Now I have edited the index.php file inside webroot like the tutorial BUT have only changed one line because I haven't moved my files OUTSIDE of the App folder like he does. So the only like I have changed is as follows:
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', '..'.DS.'..'.DS.'cake-1.3');
}
As far as I can tell that is correctly looking two directories up and finding a folder called cake-1.3 however it just gives a error 500?
Any ideas what the problem is? Thanks
EDIT:
Even doing this doesn't work???
Which If I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 and if I paste that in the address bar it loads up the cake folder so it's definitely the correct folder structure JUST it doesn't like looking at cake outside of the main url?
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3'); echo CAKE_CORE_INCLUDE_PATH;
}
You are right on the money with:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
Just make sure that Users sits in root. In other words, when you go to terminal you can get to this directory by typing: cd /Users/cameron/Sites/cake-1.3
It looks like you may be on a MAC. If so, your linking is correct. Most of the time what I find is you have done a copy paste of the app directory and it does not get the .htaccess files. I would check those first. But here is a comprehensive list of what you should verify:
Make sure the host is pointing to
the correct directory
(/Users/cameron/Sites/sample-site/)
Verify mod_rewrite is in fact on.
Verify you have copied the .htaccess
file in both the
/Users/cameron/Sites/sample-site/
and the
/Users/cameron/Sites/sample-site/webroot
directories.
Confirm that the
/Users/cameron/Sites/cake-1.3/
directory has a directory called
cake in it that contains the core.
Once all of this is confirmed, you will be good as gold!
Happy Coding!
UPDATE:
When the index.php file looks for the cake core, it will look for a directory inside the location you are pointing to for another directory called cake. So in your case:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
You must have the cake directory inside /Users/cameron/Sites/cake-1.3. Your directory structure will look like:
/Users/cameron/Sites/cake-1.3/cake
/Users/cameron/Sites/cake-1.3/cake/libs
/Users/cameron/Sites/cake-1.3/cake/config
/Users/cameron/Sites/cake-1.3/cake/console
etc.
CakePHP 3.0+
In CakePHP 3.0+ this configuration is moved out of webroot/index.php to App/Config/paths.php
If you have access to your php.ini, you can add the path to Cake core there. Doing it this way means you don't have to change webroot/index.php at all. Example in php.ini:
include_path = ".:/usr/local/lib/php:/home/something/phpinc/cakephp2/lib"
According to the CakePHP 2.x docs, this is the recommended way to share the Cake core (assuming you have access to your php.ini).
You can have only one cake core but you must have one app folder (containing MVC) by site.
Is this a misunderstanding of the folder structure of CakePHP?
From the docs (CakePHP folder structure):
The app folder will be where you work your magic: it’s where your application’s files will be placed.
The cake folder is where we’ve worked our magic. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core.
So the cake folder shouldn't change between all of your uses, therefore you have 1 copy. You can always change some of the functionality of the core by making your own changes in the app folder i.e. extending.
There is no need to edit index.php.
Just put an alias (or link in UNIX) to your cake folder in each of your sites folder. Works perfectly. Same goes for plugins and vendors folder.

CakePHP Missing Controller - but it exists

I recently downloaded cakephp-1.3.4. I set it up on my web server. I followed the advanced installation settings. My folder structure is as follows.
/common/
cakephp/
app/
etc...
/htdoc/
The /htdoc folder is the webroot; cakephp resides in the common folder.
I have configured the paths in index.php to point to this folder structure. I have the app up and running. I created a layout, the app has picked it up (along with all the css and images - all that works).
I created a posts_controller.php in cakephp/app/controllers/. Now when I try to access the following page: http://localhost/posts. I get a message that the controller cannot be found and that I should create a app/controllers/posts_controller.php (it already exists!).
Also the strange thing is using the default pages_controller works. I created an about.ctp and dropped it in app/views/pages/about.ctp. Vising http://localhost/pages/about shows up as expected.
SOLUTION:
Sam helped me solve this problem (see the long comment thread below). The problem was I had set relative paths for my ROOT folder. This messed things up. The solution is to either directly set an absolute path or call realpath with your relative path for it to be resolved into the right absolute path.
Make sure your controller class is named correctly (should be PostsController) and inherits from AppController (not strictly necessary but good practice).

Categories