Install CakePHP Plugin and Helper via Composer - cakephp

I want to install the following plugin and helper via Composer:
https://github.com/cakephp/debug_kit
https://github.com/loadsys/twitter-bootstrap-helper
Here is my composer.json:
{
"repositories": [
{
"type": "package",
"package": {
"name": "cakephp/debug_kit",
"version": "2.0",
"source": {
"url": "https://github.com/cakephp/debug_kit",
"type": "git",
"reference": "origin/2.0"
}
}
},
{
"type": "package",
"package": {
"name": "loadsys/twitter-bootstrap-helper",
"version": "2.1",
"source": {
"url": "https://github.com/loadsys/twitter-bootstrap-helper",
"type": "git",
"reference": "origin/2.1"
}
}
}
],
"require": {
"loadsys/twitter-bootstrap-helper": "2.1.*",
"cakephp/debug_kit": "2.0"
},
"config": {
"vendor-dir": "Vendor/"
},
"autoload": {
"psr-0": {
"DebugKit": "/cakephp/debug_kit/",
"TwitterBootstrap" : "/loadsys/twitter-bootstrap-helper"
}
}
}
The packages are successfully installed at Vendor/cakephp/debug_kit and Vendor/loadsys/twitter-bootstrap-helper
My issues lies in how to I load them in CakePHP. I have the following in my bootstrap.php:
require APP . 'Vendor/autoload.php';
When I attempt to load the Plugin after requiring the autoload with:
CakePlugin::load('DebugKit');
It can not be found. Similar results with loading the helper in my AppController.php with
public $helpers = array('TiwtterBootstrap');
I am a newbie to Composer and am likely missing something simple or just not grasping how to properly load them from the Vendors folder.

Everything you have done is correct, you just need to add an extra section to instruct composer where to install your plugin. Note the extra "installer-paths" sections
, it needs to point to the relative path where you want you plugin be installed.
{
"minimum-stability": "dev",
"config": {
"vendor-dir": "vendors"
},
"extra": {
"installer-paths": {
"app/Plugin/DebugKit": ["cakephp/debug_kit"],
}
},
"require" : {
"php": ">=5.4",
"cakephp/debug_kit": "2.2.*"
}
}

I was rushed this morning in my comment, here is the "extra" block I added to my composer.json:
"extra": {
"installer-paths": {
"Plugin/DebugKit": ["cakephp/debug_kit"],
"Plugin/TwitterBootstrap": ["loadsys/twitter-bootstrap-helper"]
}
Deleting my composer.lock in order to start over with the install, still didn't put the files into the Plugin folder. However, even if I got that to work, I thought it would be possible for the system to recognize the plugins from the Vendor folder via the composer autoload and perhaps some magic from Cake. That way I could just keep the entire Vendors folder out of my repository for this project and update my dependencies as needed.
I ended up solving my issue by just sym linking to these files from the Plugin folder and my system is recognizing the Plugins.

Related

Why is Google App Engine throwing access forbidden errors?

Could really use some help here. I have a GAE NodeJS app in the standard environment. Until a few days ago (09/23) it was running just fine, it would respond to requests as expected, etc.
Today, the app responds with 403's when I try to make any request to my appspot url. I'm 100% certain this is not a code issue, as if I deploy the same code to GAE in another project, it works fine. Furthermore, the only firewall rule is a wildcard to allow all traffic.
Edit: adding the only relevant-looking log entry I see from the project:
{
"protoPayload": {
"#type": "type.googleapis.com/google.cloud.audit.AuditLog",
"status": {},
"authenticationInfo": {
"principalEmail": "address#domain.com"
},
"requestMetadata": {
"callerIp": "x.x.x.x",
"requestAttributes": {
"time": "2021-09-23T15:04:05.198927Z",
"auth": {}
},
"destinationAttributes": {}
},
"serviceName": "appengine.googleapis.com",
"methodName": "google.appengine.v1.Services.UpdateService",
"authorizationInfo": [
{
"resource": "apps/my-google-cloud-project-id/services/default",
"permission": "appengine.services.update",
"granted": true,
"resourceAttributes": {}
}
],
"resourceName": "apps/my-google-cloud-project-id/services/default",
"serviceData": {
"#type": "type.googleapis.com/google.appengine.v1.AuditData",
"updateService": {
"request": {
"name": "apps/my-google-cloud-project-id/services/default",
"service": {
"networkSettings": {
"ingressTrafficAllowed": "INGRESS_TRAFFIC_ALLOWED_INTERNAL_AND_LB"
}
},
"updateMask": "networkSettings"
}
}
},
"resourceLocation": {
"currentLocations": [
"us-east1"
]
}
},
"insertId": "an-id",
"resource": {
"type": "gae_app",
"labels": {
"project_id": "my-google-cloud-project-id",
"zone": "",
"module_id": "default",
"version_id": ""
}
},
"timestamp": "2021-09-23T15:04:05.131761Z",
"severity": "NOTICE",
"logName": "projects/my-google-cloud-project-id/logs/cloudaudit.googleapis.com%2Factivity",
"operation": {
"id": "some-operation-uuid",
"producer": "appengine.googleapis.com/admin",
"first": true
},
"receiveTimestamp": "2021-09-23T15:04:05.495890906Z"
}
I don't recall making this change, and I'm not sure what the ingressTrafficAllowed value was before.
Somehow the ingress setting on the GAE service got changed. I believe that issue was fixed by going to GCP console > App Engine > Services > select affected service(s) -> Edit ingress setting from the top, and select the appropriate value.
I say I believe this fixed the issue as I was still getting 403's on my appspot url after doing this, and ultimately I ended up deleting and re-creating the project from scratch, which got everything working again. Clearly there was some misconfiguration somewhere in my project, but GCP does not make it easy to diagnose what the issue might be.

Field: android - should NOT have additional property 'enableDangerousExperimentalLeanBuilds'

My expo version is 42.0.0. When I run "expo build:android -t app-bundle", I get this error:
Error: Problem validating fields in app.json. Learn more: https://docs.expo.io/workflow/configuration/
• Field: android - should NOT have additional property 'enableDangerousExperimentalLeanBuilds'.
Couldn't publish because errors were found. (See logs above.) Please fix the errors and try again.
{
"expo": {
"name": "XXXX",
"slug": "XXXX",
"version": "1.2.0",
"orientation": "portrait",
"icon": "./assets/XXXX.png",
"splash": {
"image": "./assets/XXXX.png",
"resizeMode": "contain",
"backgroundColor": "#FBDB5B"
},
"privacy": "public",
"platforms": [
"android"
],
"android": {
"config": {
"googleMobileAdsAppId": "XXXX"
},
"package": "com.XXXX",
"versionCode": 16,
"permissions": [],
"enableDangerousExperimentalLeanBuilds": true
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"]
}
}
The thing is, the property enableDangerousExperimentalLeanBuilds was removed.. https://docs.expo.dev/versions/latest/config/app/#android. Expo wants you to use EAS Build for smaller bundle sizes. You might have to drop the field, otherwise your app might work in development, but then crash once you put it in PlayStore.
Personally, I also had to eject as I wasn't satisfied with the sizes EAS gave me.

Schema of nuget packages.lock.json file generated by locking dependencies during restore

I can enable the packages.lock.json files to be generated as described in this link:
https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#locking-dependencies
An example packages.lock.json file may look like this:
{
"version": 1,
"dependencies": {
".NETCoreApp,Version=v3.1": {
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",
"requested": "[1.0.0, )",
"resolved": "1.0.0",
"contentHash": "7D2TMufjGiowmt0E941kVoTIS+GTNzaPopuzM1/1LSaJAdJdBrVP0SkZW7AgDd0a2U1DjsIeaKG1wxGVBNLDMw=="
},
"Newtonsoft.Json": {
"type": "Direct",
"requested": "[12.0.3, )",
"resolved": "12.0.3",
"contentHash": "6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg=="
}
}
}
}
Is there documentation around the schema of this file and what it means? I notice fields like type, resolved, contentHash, etc. under the dependencies node.
Sometimes the nodes might follow these patterns:
"Microsoft.Win32.Primitives": {
"type": "Transitive",
"resolved": "4.3.0",
"contentHash": "9ZQKCWxH7Ijp9BfahvL2Zyf1cJIk8XYLF6Yjzr2yi0b2cOut/HQ31qf1ThHAgCc3WiZMdnWcfJCgN82/0UunxA==",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0",
"Microsoft.NETCore.Targets": "1.1.0",
"System.Runtime": "4.3.0"
}
}
or
"somenameclient": {
"type": "Project",
"dependencies": {
"SomeNameClientLib": "1.0.0",
"RRRBase": "1.0.0"
}
}
From what I can tell, they have not created or posted a .json schema file for the format of the NuGet packages.lock.json file. The official documentation here makes no mention of it.
The closest thing you will get are:
Description of a lock file
Lock File Format
...from the above link.

Firefox add-on host permission error on tab with PDF file

I couldn't find this exact situation elsewhere: I have a custom add-on, which I'm loading temporarily via the developer menu. In the manifest file, I'm asking for a lot of permissions already:
{
"manifest_version": 2,
"name": "...",
"version": "1.0",
"description": "...",
"homepage_url": "...",
"permissions": [
"file:///*",
"*://*/*",
"<all_urls>",
"activeTab",
"bookmarks",
"contextMenus",
"tabs"
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": {
"19": "icon.svg"
},
"default_title": "..."
}
}
I have a background script only at the moment, however a small content script snippet gets injected:
(function() {
browser.browserAction.onClicked.addListener(async (tab) => {
let executing = browser.tabs.executeScript(tab.id, {
code: "window.getSelection().toString()"
})
...
try {
let selection = await executing
...
} catch(exception) {
console.log(exception)
}
...
})
})()
The purpose is essentially to get the current selection as text (for now) in order to later upload it to a bookmarking service of sorts.
However, when I have a tab open with a PDF file (https://www.example.com/file.pdf or file:///home/foo/file.pdf), the call of the content script to window.getSelection().toString() fails, with the following error:
Error: Missing host permission for the tab
Is this expected and I'm just missing a particular permission (and which one would that be)? Or is it unexpected and possibly worthy of a bug report?
Also, the call works in the developer console, which is why I'm thinking I'm really missing permissions somehow.

install from github using composer and no composer.json in github

I try to install the plugin CakePHP-CSV using Composer. I forked it from ProLoser/CakePHP-CSV.
I don't want to install it in Vendor, but in Plugin folder and with the name of Csv and not the default one that is the plugin name. I tried to use the extra in composer.json but what ever I tried it installs it in Vendor folder of the project.
"repositories": [
{
"type": "package",
"package": {
"name": "CakePHP-CSV/Csv",
"version": "dev-master",
"source": {
"url": "https://github.com/sela/CakePHP-CSV",
"type": "git",
"reference": "origin/master"
}
}
}
],
"require": {
"CakePHP-CSV/Csv": "dev-master",
},
"config": {
"vendor-dir": "Vendor"
},
"extra": {
"installer-paths": {
"Plugin/Cvs": ["Plugin/cvs"]
}
}
You need to make your package depend on composer/installers.
From Composer's documentation:
If you are a package author and want your package installed to a custom directory, simply require composer/installers and set the appropriate type. This is common if your package is intended for a specific framework such as CakePHP, Drupal or WordPress. Here is an example composer.json file for a WordPress theme:
{
"name": "you/themename",
"type": "wordpress-theme",
"require": {
"composer/installers": "~1.0"
}
}
And later (I've added italics to the important part):
As a package consumer you can set or override the install path for a package that requires composer/installers by configuring the installer-paths extra. A useful example would be for a Drupal multisite setup where the package should be installed into your sites subdirectory.
Note that extra is simply a place to put arbitrary data:
Arbitrary extra data for consumption by scripts.
This can be virtually anything. To access it from within a script event handler, you can do:
$extra = $event->getComposer()->getPackage()->getExtra();
The second part is very important; something has to retrieve the extra data and do something with it. In this instance that something is composer/installers.
I needed more space for the code so I answer myself. The following code worked and I didn't need to fork the code.
"repositories": [
{
"type": "package",
"package": {
"name": "ProLoser/CakePHP-CSV",
"version": "1.0",
"type": "cakephp-plugin",
"dist": {
"url": "https://github.com/ProLoser/CakePHP-CSV/archive/master.zip",
"type": "zip"
}
}
}
],
"require": {
"composer/installers": "~1.0.0",
"ProLoser/CakePHP-CSV": "1.*"
},
"config": {
"vendor-dir": "Vendor"
}

Resources