Show error when a function is called inside / outside of certain folders - phpstorm

Is there a way to, for example, make PhpStorm show an error (on the function call and for the file) when function xyx() is called in any file in any folder other than in folder abc?
Specific use case if it helps:
I want to show an error where ever I use the env() function outside of the config folder in a Laravel app - because, after running php artisan config:cache, which one does when deploying a Laravel app, all calls to env() return null, and I'm worried it's easy to accidentally use env() in my codebase rather than config()

Related

yii2: model relations error can't find another class in ubuntu server 16.04

I have upload my YII2 project to ubuntu 16.04.
My source is no problem when run on localhost on my computer, but when I run it on the server ubuntu 16.04 with network, it has a problem.
The model source can't find another relation model
public function getLokasiAwal()
{
return $this->hasOne(KotaBandara::className(), ['id_kota' => 'lokasi_awal']);
}
and i have error
Class 'backend\models\TypeNonstaf' not found
I have found the solution, I added the following code:
use backend\models\Kotabandara;
On top in model file but, in my source in localhost,
I do not need to add that code
Can someone explain that issue??
As #rob006 pointed out, it appears that you had been working/running your app on a Windows local file system, which is case-preserving, but not case-sensitive.
When you first call upon a namespaced class directly or via the use operator, it passes this full class name as $className into yii\BaseYii\autoload::($className) (Yii2's global class autoloading handler), which in turn attempts to include the corresponding class file, if found.
So, on your Windows local machine, when you use backend\models\KotaBandara, it will find and include any file associated with the corresponding path alias in a case-insensitive manner, thus it will find any of:
#backend/models/KotaBandara.php
#backend/models/Kotabandara.php
#backend/models/kotabandara.php
#backend/models/KoTaBaNdArA.php
There can be only 1 target file with this sequence of paths/characters anyway.
However, when you migrate this code to a Ubuntu system, which is both case-preserving and case-sensitive, there is a distinct difference between KotaBandara.php and kotabandara.php and in fact both files can exist side by side, unlike on Windows.
So, you have to be precise here - on Ubuntu, use backend\models\KotaBandara will trigger the autoloader to find only the file whose path AND case matches, i.e. KotaBandara.php. If you named the file kotabandara.php, it will be found on Windows, but not on Ubuntu!

Filemaker - how/where to use custom function?

I have downloaded the BaseElements plugin for Filemaker and managed to get it installed, I have downloaded this specifically to make use of "BE_ExportFieldContents" (https://baseelementsplugin.zendesk.com/hc/en-us/articles/204700538-BE-ExportFieldContents) which basically allows me to export from a Container field on a server side script. I have looked through the documentation and cannot seem to find help.
Now I have the function, I'm completely at a loss on how to actually call the function? I want to export something from the container file to the filemaker documents path - so my question is, where and how the hell do I use this function in Filemaker? Apologies in advance for the noob question.
You make a script where you call this function from the record in question. This script can be run in the client, or via a schedule on FileMaker Server or via the Perform Script on Server script step.
The syntax is like this:
BE_ExportFieldContents ( field ; outputPath )
Where the ‘field’ parameter is the container field and the ‘outputPath’ is where you want the file to end up.
Usually you call such functions via the Set Variable script step. After the execution the variable contains any error or result from the call.
Note that the plugin needs to be installed and enabled on the server for it to work there.

Is it possible to make Yii2 call a function when executing php init?

I'm wondering if it's possible in Yii2 to call a function automatically when executing php init command?
I have a component/extension which has a function that I want to call only when the Yii2 app is initialized. Can this function be registered in anywhere so that it will be automatically called and is it even possible?
init (Yii Application Initialization Tool) is available for Advanced Application Template only and written in procedural style (not OOP).
Unfortunately, init does not raise any events, so you can't add any event handlers to execute custom code.
The easiest way to solve the problem is to modify init file itself, but it's not good practice, because changes can be lost on framework update (file is included in git trackable files in framework core).
My advice will be create separate console command for handling that and execute it right after php init:
php init your-custom-console-controller/action-name
If you are using deploy tools, such as Deployer, you can easily add your custom command for execution right after init.
Recipe for Yii2 Advanced Application Template exists, so you can add your custom command like so:
task('deploy:your_custom_command', function () {
cd('{{release_path}}');
run('php yii your-custom-console-controller/action-name');
});
after('deploy:init', 'deploy:your_custom_command');
Then you just run:
dep deploy production
And forget about everything what you need to do to deploy your project.
Definetely recommend to spend some time and learn it, it's worth it.

Using CakePHP 3.0 plugin

I'm currently building a new CakePHP app with version 3.0.0-RC1, and trying to install and use the jasig/phpCAS plugin. Using this guide, I've run the following command from the command prompt: composer require jasig/phpcas
This correctly copies the jasig/phpcas files into the vendor directory of my app, but one of the other files that the guide says should be updated (vendor/cakephp-plugins.php) doesn't even exist.
I've had a tough time accessing the plugin. I want to be able to call its static methods, and I keep getting errors of the form: Error: Class 'App\Controller\phpCAS' not found. (The exact directory in the error changes depending on where I'm calling the method from.)
I don't know if this is due to not having the cakephp-plugins.php file, or if I'm not calling the plugin correctly. It's my understanding that if the plugin is loaded I should just be able to call static methods on it like this: phpCAS::methodName()
First of all jasig/phpcas is not a CakePHP plugin. And the vendor/cakephp-plugins.php file is created by the CakePHP plugin installer, so if you don't see such a file, you seem to have either not installed any plugins yet, or you are not using a recent version of the installer, as the creation of this file has been introduced just recently.
Regarding the error about the class not being found, you are missing the leading namespace separator (\phpCAS::methodName()) to access the class in the global namespace, respectively you are missing a proper import (use phpCAS;) that would make the class available in the current namespace.
In case you are not familiar with namespaces, you may want to start with: http://php.net/namespaces

How to get sqldb to use a particular fbclient.dll?

I'm using sqldb to connect to Firebird from within my DLL. This fails because it cannot find fbclient.dll which is actually present in the same directory as my DLL. GetCurrentDir returns the path to the Windows system folder. Performing a SetCurrentDir with the path of the DLL successfully changes the current directory, but still it won't work. What can I do to get sqldb to use fbclient.dll at a location of my choosing?
From the wiki page seems there is no way to explicitly specify the directory from where the Firebird client library could be loaded. So as a workaround you may use the SetDllDirectory function which will add a directory provided to its only parameter to the search path used to locate DLL libraries for the application. A subsequent call to LoadLibrary function used to load the Firebird's client library will go through the search list and find it in the location you added by the SetDllDirectory function call.