Where to register autoload when the vendor is not managed with composer in Symfony 2.1? - symfony-2.1

I'm using symfony 2.1 and I want to add a library to vendors. The library do not exists in packagist. I can't manage it with composer. When I install bundles or others vendors through composer, it manage autoload for me. But where to register autoload when the vendor is not managed with composer?

You can add libraries to composer that are not in packagist.
You must add them in the repositories array of your composer.json file.
Here's how to load a github repository that has a composer.json file, even though it's not on packagist (for example a fork you would have done to fix a repository) : http://getcomposer.org/doc/02-libraries.md#publishing-to-a-vcs
And here's how to load a library that's on a git/svn repository, or a zip file : http://getcomposer.org/doc/05-repositories.md#types
An example using various possibilities:
{
"repositories": [
{
"type": "vcs",
"url": "http://github.com/igorw/monolog"
},
{
"type": "package",
"package": {
"name": "smarty/smarty",
"version": "3.1.7",
"dist": {
"url": "http://www.smarty.net/files/Smarty-3.1.7.zip",
"type": "zip"
},
"source": {
"url": "http://smarty-php.googlecode.com/svn/",
"type": "svn",
"reference": "tags/Smarty_3_1_7/distribution/"
},
"autoload": {
"classmap": [
"libs/"
]
}
}
}
],
"require": {
"monolog/monolog": "dev-bugfix",
"smarty/smarty": "3.1.*"
}
}

You should be able to use Composer for registering vendor libraries not available via packagist. I'm not entirely sure, but this should work fine:
{
"autoload": {
"psr-0": {
"Acme": "src/",
"MyVendorLib": "vendor/my-vendor/src",
"AnotherLib": "vendor/another-vendor/lib"
}
}
}

You just need to modify your composer.json file for the autoload value:
http://getcomposer.org/doc/04-schema.md#autoload
//composer.json in your symfony 2.1 project
"autoload": {
"psr-0": {
"": "src/",
"YourLibrary": "src/location/of/lib"
}
},
And then in your controller for example:
namespace Acme\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use YourLibrary\FolderName\ClassName;
class DefaultController extends Controller {
/**
* #Route("/")
* #Template()
*/
public function indexAction()
{
$lib = new ClassName();
$lib->getName();
return array('name' => $name);
}
}

Related

SPFX Package always referring content or resources from localhost instead from CDN

Can someone please let me know from where I can change this configuration so that it should refer from the CDN path instead of localhost
Below is my package-solution.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "mega-menu-sp-fx-client-side-solution",
"id": "8f49d75c-5a49-4657-b81b-0290f239350f",
"version": "10.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"features": [
{
"title": "Application Extension - Deployment of custom action.",
"description": "Deploys a custom action with ClientSideComponentId association",
"id": "0d2345df-2a49-4ce9-ba2d-bee7ad3e7a02",
"version": "10.0.0.0",
"assets": {
"elementManifests": [
"elements.xml",
"clientsideinstance.xml"
]
}
}
]
},
"paths": {
"zippedPackage": "solution/mega-menu-sp-fx.sppkg"
}
}
Below is my write-manifest.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "https://Mytenant.sharepoint.com/sites/MyTechTheme/MenuFiles"
}
I tried to figure out whats the issue. For publishing instead of gulp package-solution --ship I had used gulp package-solution so unless and until we don't mention --ship it wont take the references for CDN
So for deploying the package in SPO we need to use gulp bundle --ship and gulp package-solution --ship
As per this thread, to load SPFx assets from a CDN or SharePoint library, set the value of "includeClientSideAssets" to false.
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
...
"includeClientSideAssets": false,
...
}
}

How to use pdf.js with RequireJS?

I'm trying implementing the pdf.js in Magento2 which use RequireJS, how could I implement it since the global var below has not been accessible?
// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];
To implement it with RequireJS you must use the names to instantiate like this image below.
As you can see you can change the global var using the local pdfjsLib created by the clojure.
Reference: https://github.com/mozilla/pdf.js/issues/7287#issuecomment-348143963
This is really helpful.
If you are using oracle JET. You also need to specify these entries in path_mapping.json and viewmodel. You can't rename it to pdf or something else... Stick to this long name. It will work.
"pdfjs-dist/build/pdf": {
"cwd": "node_modules/pdfjs-dist/build",
"debug": {
"src": "pdf.js",
"path": "libs/pdfjs/dist/pdf.js"
},
"release": {
"src": "pdf.min.js",
"path": "libs/pdfjs/dist/pdf.min.js"
}
},
"pdfjs-dist/build/pdf.worker": {
"cwd": "node_modules/pdfjs-dist/build",
"debug": {
"src": "pdf.worker.js",
"path": "libs/pdfjs/dist/pdf.worker.js"
},
"release": {
"src": "pdf.worker.min.js",
"path": "libs/pdfjs/dist/pdf.worker.min.js"
}
},
// The below code should appear in your viewmodel js
pdfjsLib.GlobalWorkerOptions.workerSrc = FRONTEND_HOST + "/js/libs/pdfjs/dist/pdf.worker.js";

How to change library paths based on configuration?

I am building a native module that needs to link a static library. The path to that library. My binding.gyp file has the following appearance:
{
"targets": [
{
"target_name": "DcpServer",
"sources": [
"DcpServer.cc"
],
"include_dirs": [
"../../coratools",
"../../../boost-1.65.1"
],
"libraries": [
"<(module_root_dir)/../../coratools/release_uni64/coratools.lib"
],
"defines": [ "CSIWEB_EMBEDDED", "UNICODE", "_UNICODE" ],
"configurations": {
"Release": {
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1,
"RuntimeTypeInfo": "true"
}
}
},
"Debug": {
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1,
"RuntimeTypeInfo": "true"
}
}
}
}
}
]
}
The path to coratools.lib will vary based upon whether the debug or release configuration is selected. The problem is that node-gyp did not allow me to place the "libraries" key within the "configurations" property. Is there a way of doing what I want by making the library path conditional?
I never did discover how to do this. In the end, I switched to using cmake-js to build my native module.

Autoloading Php Packages with Hyphens

Packagist does not allow package names to have capital letters. To workaround this, it recommends using hyphens -. Thus my package name went from TableCreator to table-creator. Unfortunately, this seems to have prevented my library from autoloading with the following error message:
Class 'Company\TableCreator\DatabaseField' not found
This error message disappears as soon as I manually include the specific file rather than relying on the vendor/autoload.php file.
My packages composer.json file is as follows
{
"name": "company/table-creator",
"type": "library",
"description": "Package creating or editing MySQL tables.",
"keywords": ["mysql", "mysqli","models"],
"license": "MIT",
"authors": [
{
"name": "xxx xxx",
"email": "xxx#xxx.org",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"company\\table-creator\\": ""
}
}
}
The namespace declared in the file is still namespace Company\TableCreator;
What do I need to tweak in the composer config for the classes to autload now that the package name has a hyphen?
You need to revert the change to the PSR-4 namespace prefix:
{
"autoload": {
"psr-4": {
"Company\\TableCreator\\": ""
}
}
}

Chef, override attributes not applying to recipe

This is the cookbook I downloaded:
https://github.com/edelight/chef-mongodb
I installed Chef server, Chef workstation, and have a testnode ready to bootstrap.
A role I created:
$ knife role create mongodb_standalone_testproj
JSON format:
{
"name": "mongodb_standalone_testproj",
"description": "Deploy MongoDB standalone with override attributes",
"json_class": "Chef::Role",
"default_attributes": {
},
"override_attributes": {
"mongodb::default": {
"port": "27060",
"dbpath": "/data/"
}
},
"chef_type": "role",
"run_list": [
"recipe[mongodb::default]"
],
"env_run_lists": {
}
}
However, when I bootstrap the testnode with this role:
knife bootstrap testnode --sudo -x <omit> -P <omit> -N testnode -r 'role[mongodb_standalone_testproj]'
log here: http://pastebin.com/DWxY3vNV
Problem is, MongoDB installed and ran on testnode but the override attributes (port and dbpath) did not get applied, any clues?
Those attributes are not correct:
"override_attributes": {
"mongodb::default": {
"port": "27060",
"dbpath": "/data/"
}
},
I'm willing to bet you want:
"override_attributes": {
"mongodb": {
"config": {
"port": "27060",
"dbpath": "/data/"
}
}
},
I think you're just overriding the wrong attribute (not the full attribute). Looking at the defaults for the mongodb cookbook they list:
default['mongodb']['config']['port'] = 27017
But you are using the equivalent of:
['mongodb']['port']

Resources