How can I autoload a hook in TYPO3?
I register it in the ext_localconf.php, but it does not get autoloaded (unless I 'include' it in the same file which is of course an extremely ugly solution).
I looked into other extensions but I don't find, where the require there hooks.
Shouldn't it be autoloaded in the ext_emconf?
'autoload' => [
'psr-4' => [
'ID\\IndexedSearchAutocomplete\\' => 'Classes'
],
],
But when don't use my ugly solution I get the error, that GeneralUtility::makeInstance can't find my file.
Does this help? http://insight.helhum.io/post/130876393595/how-to-configure-class-loading-for-extensions-in
This article describes the options you have regarding class loading.
You may want to check whether your class fulfills the psr-4 standard: http://www.php-fig.org/psr/psr-4/
I assume that you are using composer in your project. Composer does the whole autoloading of classes. It "knows" all classes of extensions that were required by composer (listed in the require part of your composer.json).
Of course you can add extensions to your project without requiering them with composer. I guess, that is what you did here. In that case you have to tell composer about the classes in your composer.json.
Add a autoload section:
"autoload": {
"psr-4": {
"ID\\IndexedSearchAutocomplete\\": "web/typo3conf/ext/indexed_search_autocomplete/Classes"
}
}
Of course your FQCN have to match the path above your Classes folder (that is what psr-4 means).
After that you can type composer dump-autoload and your class should be loaded.
Related
What's the best way to identify which Visual Studio Code setting is generating / allowing various suggestions to pop up (so it can be turned off)? In particular I'd like to eliminate these three from ever showing.
Those suggestions are types from the standard library. The TypeScript service that powers VS Code's JavaScript and TypeScript language features loads these types from .d.ts files in order to understand the signatures of standard JavaScript library functions such as parseInt or Promise.
To find out where a type is coming from, try using workspace symbol search (cmdT):
In this case, these types come from the standard lib.d.ts file that TypeScript loads automatically. TypeScript will also automatically load a d.ts file for the DOM api.
To disable these suggestions, create a jsconfig.json at the root of your project with the contents:
{
"compilerOptions": {
"lib": []
}
}
This tells typescript not to include any extra typings files for the core libraries. You can also select which typings you want to include:
{
"compilerOptions": {
"lib": [
"es2015"
]
}
}
See the documentation for a list of valid lib options
If you notice any bugs with this behavior or have any suggestions on how this could be improved, please file an issue against VS Code
Update
To discover where a type suggestion is coming from, you may also be able to write:
/**
* #type {AsyncResultObjectCallback}
*/
var placeholer;
And then run go to type definition on placeholder. Even using "lib": [], you may still be seeing suggestions from #types files or node packages that include d.ts files
I have a large code base using jsdoc. We just noticed that a lot of private methods do not have the #private flag.
Is there a way to set up the config to see all methods that start with an underscore as private? I would really like to avoid having to go through hundreds of files to do it by hand.
I found the answer.
I installed this:
https://www.npmjs.com/package/jsdoc-autoprivate
which is unfortunately lacking in documentation.
In my jsdoc.conf.json, under source, I had to add it as a plugin:
"plugins": [
"node_modules/jsdoc-autoprivate/autoprivate.js"
]
And it works.
In case someone else found this question, jsdoc includes a plugin called underscore which does this nicely:
"plugins": [
"plugins/underscore.js"
]
How to call a class into my extension using autoload. I am using typo3 7.6. From the tutorials I understood that, for typo3 7.6, this can be done in ext_emconf.php file. How to write the same in ext_emconf.php??
My class file is in Classes/class.x.php.
All classes are automatically registered in an autoload function as long as you follow the code conventions:
https://docs.typo3.org/typo3cms/ExtbaseFluidBook/a-CodingGuidelines/Index.html
class.x.php is not a valid filename for a class in Extbase. If you want to create a ClassX then the filename has to be:
/your_extension/Classes/ClassX.php
<?php
namespace YourName\YourExtension;
class ClassX {
}
Note that the extension name also turns in UpperCamelCase. For the vendor part (YourName in the example) you can chose anything that is valid in PHP.
now you can access you class with
$test = new \YourName\YourExtension\ClassX();
Your extension obviously needs to be installed to work.
!!! Keep in mind, that Typo3 only generates the autoload cache when you install / uninstall an extension. If you add new files to an already installed extension you have to delete this cache file manually
/typo3temp/autoload/autoload_classmap.php
To configurate autoloading of classes that do no match the default naming you can create an ext_autoload.php in your extension. Inside the code looks like that:
<?php
return array(
'Tx_SomeExtension_Someclass' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('some_extension') . 'pi1/someclass.php',
);
If you are developing for Typo3 7.x, keep in mind that pibased is outdated and is only supported with the compatibility extension that brings a lot of drawbacks in performance. I would recommend not to use pibased extension any more.
If I have a package hierarchy in Scala like this:
package toplevel {
package a {
// some interesting stuff
}
package b {
// more interesting stuff
}
package utility {
// stuff that should not be accessible from the outside
// and is not logically related to the project,
// basically some helper objects
}
}
how can I forbid the users of package toplevel to see or import package utility?
I tried with private[toplevel] package utility { ... but got this error: expected start of definition.
I've searched for this and was overwhelmed by false positives: everything I got was about making things package-private and this is not my question.
You can't: packages don't have access levels.
Or rather, you can, by using OSGi and not exporting them, but this is a very heavy-weight solution if you don't need it for some other reason as well.
To reach the same goal as private packages in Java you can use augmented access modifiers. Inside your package utility you restrict access with private[utility]. This way the package member is available only inside the package utility itself.
Hope that helps.
You can only define the enclosing package, within which the code is defined
Answered here.
I am using the password confirmation validator from the official Zend framwork document here:
http://framework.zend.com/manual/en/zend.form.elements.html
In Bootstrap.php, I have set the namespace as
'namespace' => 'My_'
The file is located at
application/validate/PasswordConfirmation.php
However, "Fatal error: Class 'My_Validate_PasswordConfirmation' not found" occurs in my Zend_Form.
What should I do to fix the problem?
I designed and implemented Zend_Filter_Input, including its namespace feature.
You have a backwards understanding of how this feature works. It's meant to allow you to use a short name for a validator class when the actual name of that class is longer. You're apparently doing the reverse, trying to name a class with a longer name than it actually has.
To fix this I recommend the following steps:
Name the class My_Validate_PasswordConfirmation
Put it in `application/My/Validate/PasswordConfirmation.php
Add namespace=>'My_Validate' to your Zend_Filter_Input options.
Invoke the validator as simply "PasswordConfirmation".
update: I spent some time on this. It seems my first idea was off target. The namespace issue you have has nothing to do with the feature of Zend_Filter_Input, it has to do with the Zend_Application bootstrap feature. It seems that you can specify a class prefix to the autoloader.
Here's another clue:
Zend_Loader_Autoloader_Resource makes
the assumption that all code you are
autoloading will use an underscore
separator between namespaces,
components, and classes. As a result,
you do not need to use the trailing
underscore when registering a resource
autoloader.
So try this:
'namespace' => 'My',
with no trailing underscore.