Popular New Releases in Composer
symfony
v6.0.7
composer
2.3.4
console
v6.0.7
thanks
laravel-mongodb
v3.9.0
Popular Libraries in Composer
by symfony php
26732 MIT
The Symfony PHP framework
by composer php
26405 MIT
Dependency Manager for PHP
by CachetHQ php
12656 BSD-3-Clause
📛 An open source status page system for everyone.
by symfony php
9096 MIT
The Console component eases the creation of beautiful and testable command line interfaces.
by symfony php
7465 MIT
Give thanks (in the form of a GitHub ★) to your fellow PHP package maintainers (not limited to Symfony components)!
by hirak php
6325 MIT
composer parallel install plugin
by jenssegers php
5966 MIT
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
by vinkla php
4508 MIT
A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
by symfony php
3800 MIT
Composer plugin for Symfony
Trending New libraries in Composer
by fabpot go
850 AGPL-3.0
PHP security vulnerabilities checker
by tal-tech php
565 Apache-2.0
Fend 是一款短小精悍,可在 FPM/Swoole 服务容器平滑切换的高性能PHP框架
by spatie php
480 MIT
Use PHP 8 attributes to register routes in a Laravel app
by repman-io php
381 MIT
Repman - PHP Repository Manager: packagist proxy and host for private packages
by hyperf-admin php
268
hyperf-admin 是基于 hyperf + vue 的配置化后台开发工具
by ajthinking php
202
Edit PHP files programmatically
by Tusko javascript
181
Script gets you access to download private videos on Vimeo
by takayukister php
156 NOASSERTION
Contact Form 7 - Just another contact form plugin for WordPress.
by f9webltd php
140 MIT
:space_invader: Gracefully restrict deletion of Laravel Eloquent models
Top Authors in Composer
1
15 Libraries
657
2
11 Libraries
7665
3
10 Libraries
53733
4
10 Libraries
162
5
10 Libraries
3647
6
10 Libraries
400
7
9 Libraries
1801
8
8 Libraries
1500
9
8 Libraries
224
10
8 Libraries
46
1
15 Libraries
657
2
11 Libraries
7665
3
10 Libraries
53733
4
10 Libraries
162
5
10 Libraries
3647
6
10 Libraries
400
7
9 Libraries
1801
8
8 Libraries
1500
9
8 Libraries
224
10
8 Libraries
46
Trending Kits in Composer
No Trending Kits are available at this moment for Composer
Trending Discussions on Composer
Change behaviour of AutoFixture with AutoMoq to return false for methods
Is it possible to add settings to "allow-plugins" in config section in composer.json through the CLI?
"env: php: No such file or directory" on new mac OS Monterey
Expo SDK 44 upgrade ERROR - App.js: [BABEL]: Unexpected token '.'
Wrong PHP Version/Executable in VSCode terminal but works perfectly in Mac terminal
Wrong PHP version used when installing composer with Alpine's apk command
Android Instrumented tests with KodeIn
How to use .svg file in Jetpack Compose for Desktop?
Keeps giving Undefined variable error in routing framework code
Can't install bash in multiarch build on Alpine
QUESTION
Change behaviour of AutoFixture with AutoMoq to return false for methods
Asked 2022-Mar-31 at 09:22Say that I have the following interface:
1public interface ITeam
2{
3 bool HasPlayer(IPlayer player);
4 void AddPlayer(IPlayer player);
5}
6
I currently have a test that looks something along the lines of (using AutoMoq):
1public interface ITeam
2{
3 bool HasPlayer(IPlayer player);
4 void AddPlayer(IPlayer player);
5}
6[Theory]
7[MyAutoData]
8public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
9{
10 player.RosterToTeam(mockedTeam.Object);
11
12 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
13}
14
However, a precondition in my code is that HasPlayer
must return false for the test to pass when RosterToTeam
is called.
This can be solved by creating a ICustomization
and directly composing the correct behaviour, for example:
1public interface ITeam
2{
3 bool HasPlayer(IPlayer player);
4 void AddPlayer(IPlayer player);
5}
6[Theory]
7[MyAutoData]
8public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
9{
10 player.RosterToTeam(mockedTeam.Object);
11
12 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
13}
14public class TeamCustomization : ICustomization
15{
16 public void Customize(IFixture fixture)
17 {
18 fixture.Customize<Mock<ITeam>>(composer =>
19 composer.Do(mock =>
20 mock.Setup(team => team.HasPlayer(It.IsAny<IPlayer>()))
21 .Returns(false)));
22 }
23}
24
However, I'd like my tests always to assume that the boolean methods have a default value of false. I've tried looking into ISpecimenBuilder
, but couldn't see a way to achieve this, as it seems to only work on properties, parameters, etc.
Is anyone able to recommend me a way of generically setting up all boolean methods to return false by default when created in this fashion?
Edit: The culprit behind the behaviour change is when ConfigureMembers = true
is set for AutoMoqCustomization
.
This is what my MyAutoDataAttribute
currently looks like:
1public interface ITeam
2{
3 bool HasPlayer(IPlayer player);
4 void AddPlayer(IPlayer player);
5}
6[Theory]
7[MyAutoData]
8public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
9{
10 player.RosterToTeam(mockedTeam.Object);
11
12 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
13}
14public class TeamCustomization : ICustomization
15{
16 public void Customize(IFixture fixture)
17 {
18 fixture.Customize<Mock<ITeam>>(composer =>
19 composer.Do(mock =>
20 mock.Setup(team => team.HasPlayer(It.IsAny<IPlayer>()))
21 .Returns(false)));
22 }
23}
24public class MyAutoDataAttribute : AutoDataAttribute
25{
26 public MyAutoDataAttribute() : base(Create)
27 {
28 }
29
30 private static IFixture Create()
31 {
32 var fixture = new Fixture();
33
34 fixture.Customize(new AutoMoqCustomization
35 {
36 ConfigureMembers = true
37 });
38
39 fixture.Customize(new TeamCustomization());
40
41 return fixture;
42 }
43}
44
For my use case, ConfigureMembers = true
is still needed (and would like to remove the TeamCustomization
).
ANSWER
Answered 2022-Mar-26 at 16:40First of all, you may want to use AutoMoqDataAttribute to create a mock of the ITeam
interface:
1public interface ITeam
2{
3 bool HasPlayer(IPlayer player);
4 void AddPlayer(IPlayer player);
5}
6[Theory]
7[MyAutoData]
8public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
9{
10 player.RosterToTeam(mockedTeam.Object);
11
12 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
13}
14public class TeamCustomization : ICustomization
15{
16 public void Customize(IFixture fixture)
17 {
18 fixture.Customize<Mock<ITeam>>(composer =>
19 composer.Do(mock =>
20 mock.Setup(team => team.HasPlayer(It.IsAny<IPlayer>()))
21 .Returns(false)));
22 }
23}
24public class MyAutoDataAttribute : AutoDataAttribute
25{
26 public MyAutoDataAttribute() : base(Create)
27 {
28 }
29
30 private static IFixture Create()
31 {
32 var fixture = new Fixture();
33
34 fixture.Customize(new AutoMoqCustomization
35 {
36 ConfigureMembers = true
37 });
38
39 fixture.Customize(new TeamCustomization());
40
41 return fixture;
42 }
43}
44public class AutoMoqDataAttribute : AutoDataAttribute
45{
46 public AutoMoqDataAttribute()
47 : base(new Fixture().Customize(new AutoMoqCustomization()))
48 {
49 }
50}
51
There is no need in cusomizing fixture to configure your mocks. You'd better do that in the tests itself (the arrange section):
1public interface ITeam
2{
3 bool HasPlayer(IPlayer player);
4 void AddPlayer(IPlayer player);
5}
6[Theory]
7[MyAutoData]
8public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
9{
10 player.RosterToTeam(mockedTeam.Object);
11
12 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
13}
14public class TeamCustomization : ICustomization
15{
16 public void Customize(IFixture fixture)
17 {
18 fixture.Customize<Mock<ITeam>>(composer =>
19 composer.Do(mock =>
20 mock.Setup(team => team.HasPlayer(It.IsAny<IPlayer>()))
21 .Returns(false)));
22 }
23}
24public class MyAutoDataAttribute : AutoDataAttribute
25{
26 public MyAutoDataAttribute() : base(Create)
27 {
28 }
29
30 private static IFixture Create()
31 {
32 var fixture = new Fixture();
33
34 fixture.Customize(new AutoMoqCustomization
35 {
36 ConfigureMembers = true
37 });
38
39 fixture.Customize(new TeamCustomization());
40
41 return fixture;
42 }
43}
44public class AutoMoqDataAttribute : AutoDataAttribute
45{
46 public AutoMoqDataAttribute()
47 : base(new Fixture().Customize(new AutoMoqCustomization()))
48 {
49 }
50}
51[Theory, AutoMoqData]
52public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
53{
54 mockedTeam.Setup(t => t.HasPlayer(player)).Returns(false);
55 player.RosterToTeam(mockedTeam.Object);
56 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
57}
58
59[Theory, AutoMoqData]
60public void ShouldNotRosterToTeamWhenPlayerIsRostered(Player player, Mock<ITeam> mockedTeam)
61{
62 mockedTeam.Setup(t => t.HasPlayer(player)).Returns(true);
63 player.RosterToTeam(mockedTeam.Object);
64 mockedTeam.Verify(team => team.AddPlayer(player), Times.Never);
65}
66
and, finaly, the simplified RoastToTeam implementation:
1public interface ITeam
2{
3 bool HasPlayer(IPlayer player);
4 void AddPlayer(IPlayer player);
5}
6[Theory]
7[MyAutoData]
8public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
9{
10 player.RosterToTeam(mockedTeam.Object);
11
12 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
13}
14public class TeamCustomization : ICustomization
15{
16 public void Customize(IFixture fixture)
17 {
18 fixture.Customize<Mock<ITeam>>(composer =>
19 composer.Do(mock =>
20 mock.Setup(team => team.HasPlayer(It.IsAny<IPlayer>()))
21 .Returns(false)));
22 }
23}
24public class MyAutoDataAttribute : AutoDataAttribute
25{
26 public MyAutoDataAttribute() : base(Create)
27 {
28 }
29
30 private static IFixture Create()
31 {
32 var fixture = new Fixture();
33
34 fixture.Customize(new AutoMoqCustomization
35 {
36 ConfigureMembers = true
37 });
38
39 fixture.Customize(new TeamCustomization());
40
41 return fixture;
42 }
43}
44public class AutoMoqDataAttribute : AutoDataAttribute
45{
46 public AutoMoqDataAttribute()
47 : base(new Fixture().Customize(new AutoMoqCustomization()))
48 {
49 }
50}
51[Theory, AutoMoqData]
52public void ShouldRosterToTeamWhenPlayerIsNotRostered(Player player, Mock<ITeam> mockedTeam)
53{
54 mockedTeam.Setup(t => t.HasPlayer(player)).Returns(false);
55 player.RosterToTeam(mockedTeam.Object);
56 mockedTeam.Verify(team => team.AddPlayer(player), Times.Once);
57}
58
59[Theory, AutoMoqData]
60public void ShouldNotRosterToTeamWhenPlayerIsRostered(Player player, Mock<ITeam> mockedTeam)
61{
62 mockedTeam.Setup(t => t.HasPlayer(player)).Returns(true);
63 player.RosterToTeam(mockedTeam.Object);
64 mockedTeam.Verify(team => team.AddPlayer(player), Times.Never);
65}
66public class Player
67{
68 public void RosterToTeam(ITeam team)
69 {
70 if (team.HasPlayer(this))
71 {
72 return;
73 }
74 team.AddPlayer(this);
75 }
76}
77
QUESTION
Is it possible to add settings to "allow-plugins" in config section in composer.json through the CLI?
Asked 2022-Mar-29 at 08:31Since composer 2.2 the setting allow-plugins
will be compulsory I’ve tried to push this setting through the composer config
command in the CLI but with no luck.
I’ve tried a few commands like:
composer config --json '{"allow-plugins.composer/installers":true, "allow-plugins.dealerdirect/phpcodesniffer-composer-installer": true, "allow-plugins.roots/wordpress-core-installer": true }'
composer config config.allow-plugins '{"composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "wordpress-core-installer": true}'
composer config --append "allow-plugins" "composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "wordpress-core-installer": true
composer config --json "allow-plugins" '{"composer/installers":true, "dealerdirect/phpcodesniffer-composer-installer": true, "roots/wordpress-core-installer": true }'
All I get is error messages like ".. is not defined" or that it is an invalid value.
What I have is this:
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5
And, I need to add the settings like this:
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5"config": {
6 "optimize-autoloader": true,
7 "preferred-install": "dist",
8 "allow-plugins": {
9 "composer/installers": true,
10 "dealerdirect/phpcodesniffer-composer-installer": true,
11 "roots/wordpress-core-installer": true
12 }
13},
14
Is this possible through the CLI?
ANSWER
Answered 2022-Mar-29 at 08:31You need to pass set them one by one.
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5"config": {
6 "optimize-autoloader": true,
7 "preferred-install": "dist",
8 "allow-plugins": {
9 "composer/installers": true,
10 "dealerdirect/phpcodesniffer-composer-installer": true,
11 "roots/wordpress-core-installer": true
12 }
13},
14composer config allow-plugins.composer/installers true
15composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
16composer config allow-plugins.roots/wordpress-core-installer true
17
Edit per conversation in comments:
OP was looking to also achieve not being prompted during the command. To do this, we must pass the --no-interaction
(or -n
) option. This can be useful when performing automation tasks.
Full Example of OP's Plugins:
1 "config": {
2 "optimize-autoloader": true,
3 "preferred-install": "dist"
4},
5"config": {
6 "optimize-autoloader": true,
7 "preferred-install": "dist",
8 "allow-plugins": {
9 "composer/installers": true,
10 "dealerdirect/phpcodesniffer-composer-installer": true,
11 "roots/wordpress-core-installer": true
12 }
13},
14composer config allow-plugins.composer/installers true
15composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
16composer config allow-plugins.roots/wordpress-core-installer true
17composer config --no-interaction allow-plugins.composer/installerstrue
18composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
19composer config --no-interaction allow-plugins.roots/wordpress-core-installer true
20
QUESTION
"env: php: No such file or directory" on new mac OS Monterey
Asked 2022-Mar-09 at 14:19i've updated my mac os to Monterey (12) and then I can not use composer command or php command and get this error
1env: php: No such file or directory
2
ANSWER
Answered 2021-Oct-28 at 08:10PHP has been removed from MacOS since v12 (Monterey), so you first need to install it on your own to use it. From my POV, the easiest way to do this is using Homebrew
QUESTION
Expo SDK 44 upgrade ERROR - App.js: [BABEL]: Unexpected token '.'
Asked 2022-Jan-24 at 21:48I have recently upgraded my app from SDK 40 to SDK 44 and came across this error App.js: [BABEL]: Unexpected token '.' (While processing: /Users/user/path/to/project/node_modules/babel-preset-expo/index.js)
Error Stack Trace:
1App.js: [BABEL]: Unexpected token '.' (While processing: /Users/user/path/to/project/node_modules/babel-preset-expo/index.js)
2/Users/user/path/to/project/node_modules/babel-preset-expo/index.js:48
3 ...(options?.jsxRuntime !== 'classic' && {
4 ^
5
6SyntaxError: Unexpected token '.'
7 at wrapSafe (internal/modules/cjs/loader.js:931:16)
8 at Module._compile (internal/modules/cjs/loader.js:979:27)
9 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
10 at Module.load (internal/modules/cjs/loader.js:879:32)
11 at Function.Module._load (internal/modules/cjs/loader.js:724:14)
12 at Module.require (internal/modules/cjs/loader.js:903:19)
13 at require (internal/modules/cjs/helpers.js:74:18)
14 at loadCjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:85:18)
15 at loadCjsOrMjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:57:16)
16
Here is my babel.config.js:
1App.js: [BABEL]: Unexpected token '.' (While processing: /Users/user/path/to/project/node_modules/babel-preset-expo/index.js)
2/Users/user/path/to/project/node_modules/babel-preset-expo/index.js:48
3 ...(options?.jsxRuntime !== 'classic' && {
4 ^
5
6SyntaxError: Unexpected token '.'
7 at wrapSafe (internal/modules/cjs/loader.js:931:16)
8 at Module._compile (internal/modules/cjs/loader.js:979:27)
9 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
10 at Module.load (internal/modules/cjs/loader.js:879:32)
11 at Function.Module._load (internal/modules/cjs/loader.js:724:14)
12 at Module.require (internal/modules/cjs/loader.js:903:19)
13 at require (internal/modules/cjs/helpers.js:74:18)
14 at loadCjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:85:18)
15 at loadCjsOrMjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:57:16)
16return {
17 presets: ['babel-preset-expo', { jsxRuntime: 'automatic' }],
18 plugins: [
19 ['inline-dotenv'],
20 ['.....']
21 ]
22}
23
Here is my package.json:
1App.js: [BABEL]: Unexpected token '.' (While processing: /Users/user/path/to/project/node_modules/babel-preset-expo/index.js)
2/Users/user/path/to/project/node_modules/babel-preset-expo/index.js:48
3 ...(options?.jsxRuntime !== 'classic' && {
4 ^
5
6SyntaxError: Unexpected token '.'
7 at wrapSafe (internal/modules/cjs/loader.js:931:16)
8 at Module._compile (internal/modules/cjs/loader.js:979:27)
9 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
10 at Module.load (internal/modules/cjs/loader.js:879:32)
11 at Function.Module._load (internal/modules/cjs/loader.js:724:14)
12 at Module.require (internal/modules/cjs/loader.js:903:19)
13 at require (internal/modules/cjs/helpers.js:74:18)
14 at loadCjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:85:18)
15 at loadCjsOrMjsDefault (/Users/user/path/to/project/node_modules/@babel/core/lib/config/files/module-types.js:57:16)
16return {
17 presets: ['babel-preset-expo', { jsxRuntime: 'automatic' }],
18 plugins: [
19 ['inline-dotenv'],
20 ['.....']
21 ]
22}
23{
24 "main": "node_modules/expo/AppEntry.js",
25 "scripts": {
26 "start": "expo start",
27 "android": "expo start --android",
28 "ios": "expo start --ios",
29 "web": "expo start --web",
30 "eject": "expo eject",
31 "test": "jest"
32 },
33 "jest": {
34 "preset": "jest-expo"
35 },
36 "dependencies": {
37 "@babel/plugin-transform-react-jsx": "^7.16.5",
38 "@react-native-async-storage/async-storage": "~1.15.0",
39 "@react-native-community/art": "^1.2.0",
40 "@react-native-community/datetimepicker": "4.0.0",
41 "@react-native-community/masked-view": "0.1.10",
42 "@react-native-community/netinfo": "7.1.3",
43 "@react-native-community/push-notification-ios": "^1.2.2",
44 "@react-native-community/slider": "4.1.12",
45 "@react-navigation/native": "^5.1.4",
46 "aws-amplify": "^3.3.1",
47 "aws-amplify-react-native": "^4.2.6",
48 "axios": "^0.19.2",
49 "expo": "^44.0.0",
50 "expo-app-loading": "~1.3.0",
51 "expo-barcode-scanner": "~11.2.0",
52 "expo-camera": "~12.1.0",
53 "expo-constants": "~13.0.0",
54 "expo-font": "~10.0.4",
55 "expo-linking": "~3.0.0",
56 "expo-mail-composer": "~11.1.0",
57 "expo-notifications": "~0.14.0",
58 "expo-permissions": "~13.1.0",
59 "expo-secure-store": "~11.1.0",
60 "expo-sqlite": "~10.1.0",
61 "expo-updates": "~0.11.2",
62 "expo-web-browser": "~10.1.0",
63 "file-saver": "^2.0.2",
64 "jsbarcode": "^3.11.3",
65 "link": "^0.1.5",
66 "metro-config": "^0.64.0",
67 "npm": "^8.3.0",
68 "qs": "^6.9.4",
69 "react": "17.0.1",
70 "react-dom": "17.0.1",
71 "react-native": "https://github.com/expo/react-native/archive/sdk-44.0.0.tar.gz",
72 "react-native-barcode-expo": "^1.1.1",
73 "react-native-elements": "^3.2.0",
74 "react-native-fs": "^2.16.6",
75 "react-native-gesture-handler": "~2.1.0",
76 "react-native-modal": "^11.5.6",
77 "react-native-modal-datetime-picker": "^8.6.0",
78 "react-native-paper": "^3.10.1",
79 "react-native-push-notification": "^3.5.2",
80 "react-native-reanimated": "~2.3.1",
81 "react-native-router-flux": "^4.2.0",
82 "react-native-safe-area-context": "3.3.2",
83 "react-native-screens": "~3.10.1",
84 "react-native-snap-carousel": "^3.9.1",
85 "react-native-svg": "12.1.1",
86 "react-native-web": "0.17.1",
87 "react-navigation-animated-switch": "^0.6.4",
88 "react-navigation-drawer": "^2.4.11",
89 "react-navigation-header-buttons": "^3.0.5",
90 "react-router-dom": "^6.0.0-alpha.3",
91 "yarn": "^1.22.17"
92 },
93 "devDependencies": {
94 "@babel/core": "^7.12.9",
95 "@babel/runtime": "^7.9.2",
96 "@react-native-community/eslint-config": "^0.0.7",
97 "babel-jest": "^25.1.0",
98 "babel-plugin-inline-dotenv": "^1.6.0",
99 "babel-preset-expo": "9.0.1",
100 "eslint": "^6.8.0",
101 "expo-cli": "^5.0.2",
102 "jest": "^26.6.3",
103 "jest-expo": "^44.0.0",
104 "metro-react-native-babel-preset": "^0.66.2",
105 "react-test-renderer": "^16.13.1"
106 },
107 "private": true
108}
109
Any help will be greatly appreciated.
ANSWER
Answered 2021-Dec-21 at 05:52can you give your
- package.json
- node version
I think that's because of the babel issue / your node version, because it cannot transpile the optional chaining https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
maybe tried using latest LTS node version? because as far as I know, the latest LTS node version already support optional chaining
QUESTION
Wrong PHP Version/Executable in VSCode terminal but works perfectly in Mac terminal
Asked 2021-Dec-30 at 12:35I just updated my Mac M1 to Big Sur 11.5.2 and something in VSCode seems to have broken. I am unable to use the latest home-brew php which is installed.
In VSCode its pointing to /usr/bin/php which is Macs built in php, that's not the one im using with home-brew. I tried everything and changed the path but still the same thing.
I checked the one similar question to mine and all it suggests is to use Homebrew which I already am doing so Im not sure what I am doing wrong here.
I am running PHPUnit tests in the VSCode terminal and I am getting the following error:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6
However when I run the same thing in the Mac terminal by going to the same folder it works perfectly:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26
When I do which php in both terminals I get a different result:
In Mac terminal:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28
In VSCode terminal:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28/Users/themyth/App/Sites/MapFramework/map -> which php
29/usr/bin/php
30/Users/themyth/App/Sites/MapFramework/map ->
31
How can I point VSCode to the right version of PHP? I don't think this happened before doing the Big Sur update and I am not sure what to edit.
I tried to open settings.json but I can't find any info about this and I am not sure how to edit this.
Any advice would be appreciated.
Edit 1:
I think this issue happened since I installed PHPIntellisense on VSCode but can't be sure, what I do know is that it was working before. I dont know how to configure VSCode to point to the home-brew PHP which is already installed and working perfectly in the regular terminal
Edit 2
I tried to edit settings.json and it made no difference:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28/Users/themyth/App/Sites/MapFramework/map -> which php
29/usr/bin/php
30/Users/themyth/App/Sites/MapFramework/map ->
31{
32 "workbench.colorTheme": "Monokai Dimmed",
33 "security.workspace.trust.untrustedFiles": "open",
34 "redhat.telemetry.enabled": false,
35 "php.validate.executablePath": "/opt/homebrew/bin/php",
36 "php.executablePath": "/opt/homebrew/bin/php"
37}
38
Edit 3
I have completely uninstalled VSCode and reinstalled everything. To start from fresh and the same problem happens. This is what the current settings.json file looks like:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28/Users/themyth/App/Sites/MapFramework/map -> which php
29/usr/bin/php
30/Users/themyth/App/Sites/MapFramework/map ->
31{
32 "workbench.colorTheme": "Monokai Dimmed",
33 "security.workspace.trust.untrustedFiles": "open",
34 "redhat.telemetry.enabled": false,
35 "php.validate.executablePath": "/opt/homebrew/bin/php",
36 "php.executablePath": "/opt/homebrew/bin/php"
37}
38{
39 "workbench.colorTheme": "Default Dark+",
40 "php.validate.executablePath": "/opt/homebrew/bin/php"
41}
42
When I do which php in the terminal in VSCode I always get the same thing /usr/bin/php
The same problem is continuing, Im not sure if this is because of the OSX update.
How could I configure the VSCode terminal to be exactly like the Mac terminal?
I also opened another project where I am using Symfony and I am trying to create a basic controller & that doesn't work too. I have edited the question to be more generic now:
php bin/console make:controller test I get the following error:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28/Users/themyth/App/Sites/MapFramework/map -> which php
29/usr/bin/php
30/Users/themyth/App/Sites/MapFramework/map ->
31{
32 "workbench.colorTheme": "Monokai Dimmed",
33 "security.workspace.trust.untrustedFiles": "open",
34 "redhat.telemetry.enabled": false,
35 "php.validate.executablePath": "/opt/homebrew/bin/php",
36 "php.executablePath": "/opt/homebrew/bin/php"
37}
38{
39 "workbench.colorTheme": "Default Dark+",
40 "php.validate.executablePath": "/opt/homebrew/bin/php"
41}
42Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS)
43
What is most frustrating is this seems so straight forward I can't understand what I need to do to fix this
ANSWER
Answered 2021-Aug-25 at 09:40I got the same problem. Open your terminal and write this:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28/Users/themyth/App/Sites/MapFramework/map -> which php
29/usr/bin/php
30/Users/themyth/App/Sites/MapFramework/map ->
31{
32 "workbench.colorTheme": "Monokai Dimmed",
33 "security.workspace.trust.untrustedFiles": "open",
34 "redhat.telemetry.enabled": false,
35 "php.validate.executablePath": "/opt/homebrew/bin/php",
36 "php.executablePath": "/opt/homebrew/bin/php"
37}
38{
39 "workbench.colorTheme": "Default Dark+",
40 "php.validate.executablePath": "/opt/homebrew/bin/php"
41}
42Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS)
43nano ~/.zshrc
44
At the top of the file you have this:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28/Users/themyth/App/Sites/MapFramework/map -> which php
29/usr/bin/php
30/Users/themyth/App/Sites/MapFramework/map ->
31{
32 "workbench.colorTheme": "Monokai Dimmed",
33 "security.workspace.trust.untrustedFiles": "open",
34 "redhat.telemetry.enabled": false,
35 "php.validate.executablePath": "/opt/homebrew/bin/php",
36 "php.executablePath": "/opt/homebrew/bin/php"
37}
38{
39 "workbench.colorTheme": "Default Dark+",
40 "php.validate.executablePath": "/opt/homebrew/bin/php"
41}
42Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS)
43nano ~/.zshrc
44# If you come from bash you might have to change your $PATH.
45# export PATH=$HOME/bin:/usr/local/bin:$PATH
46
Put this line just under:
1/Users/themyth/App/Sites/MapFramework/map -> ./vendor/bin/phpunit tests
2/usr/bin/php declares an invalid value for PHP_VERSION.
3This breaks fundamental functionality such as version_compare().
4Please use a different PHP interpreter.
5/Users/themyth/App/Sites/MapFramework/map ->
6/Users/themyth/app/Sites/MapFramework/Map -> ./vendor/bin/phpunit tests
7PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
8
9Runtime: PHP 8.0.9
10Configuration: /Users/themyth/App/Sites/MapFramework/Map/phpunit.xml
11
12...R 4 / 4 (100%)
13
14Time: 00:00.004, Memory: 6.00 MB
15
16There was 1 risky test:
17
181) tests\map\core\exception\MapExceptionTest::testDisplayMethodShowsBasicStaticHtml
19This test did not perform any assertions
20
21/Users/themyth/App/Sites/MapFramework/Map/tests/map/core/exception/MapExceptionTest.php:16
22
23OK, but incomplete, skipped, or risky tests!
24Tests: 4, Assertions: 4, Risky: 1.
25/Users/themyth/app/Sites/MapFramework/Map ->
26/Users/themyth/app/Sites/MapFramework/Map -> which php
27/opt/homebrew/bin/php
28/Users/themyth/App/Sites/MapFramework/map -> which php
29/usr/bin/php
30/Users/themyth/App/Sites/MapFramework/map ->
31{
32 "workbench.colorTheme": "Monokai Dimmed",
33 "security.workspace.trust.untrustedFiles": "open",
34 "redhat.telemetry.enabled": false,
35 "php.validate.executablePath": "/opt/homebrew/bin/php",
36 "php.executablePath": "/opt/homebrew/bin/php"
37}
38{
39 "workbench.colorTheme": "Default Dark+",
40 "php.validate.executablePath": "/opt/homebrew/bin/php"
41}
42Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.3.24-(to be removed in future macOS)
43nano ~/.zshrc
44# If you come from bash you might have to change your $PATH.
45# export PATH=$HOME/bin:/usr/local/bin:$PATH
46export PATH=/opt/homebrew/opt/php@8.0/bin:$PATH
47
Save and close, restart your terminal and it will normally work.
NB: I write php@8.0 but you can do this with all versions you install with homebrew
QUESTION
Wrong PHP version used when installing composer with Alpine's apk command
Asked 2021-Dec-23 at 11:20I've got a docker image running 8.0 and want to upgrade to 8.1. I have updated the image to run with PHP 8.1 and want to update the dependencies in it.
The new image derives from php:8.1.1-fpm-alpine3.15
I've updated the composer.json
and changed require.php
to ^8.1
but ran into the following message when running composer upgrade
:
1Root composer.json requires php ^8.1 but your php version (8.0.14) does not satisfy that requirement.
2
What I find dazzling is that the composer incorrectly identifies PHP version. I used two commands to determine that:
1Root composer.json requires php ^8.1 but your php version (8.0.14) does not satisfy that requirement.
2which php # returns only /usr/local/bin/php
3/usr/local/bin/php -v # returns PHP 8.1.1 (cli) (built: Dec 18 2021 01:38:53) (NTS)
4
So far I've tried:
- Checking
php -v
- Clearing composer cache
- Rebuilding image
Composer version 2.1.12 2021-11-09 16:02:04
1Root composer.json requires php ^8.1 but your php version (8.0.14) does not satisfy that requirement.
2which php # returns only /usr/local/bin/php
3/usr/local/bin/php -v # returns PHP 8.1.1 (cli) (built: Dec 18 2021 01:38:53) (NTS)
4composer check-platform-reqs | grep php
5# returns:
6# ...
7# php 8.0.14 project/name requires php (^8.1) failed
8
All of the commands above (excluding docker commands) are being ran in the container
Dockerfile:
1Root composer.json requires php ^8.1 but your php version (8.0.14) does not satisfy that requirement.
2which php # returns only /usr/local/bin/php
3/usr/local/bin/php -v # returns PHP 8.1.1 (cli) (built: Dec 18 2021 01:38:53) (NTS)
4composer check-platform-reqs | grep php
5# returns:
6# ...
7# php 8.0.14 project/name requires php (^8.1) failed
8FROM php:8.1.1-fpm-alpine3.15
9
10ENV TZ=Europe/London
11
12# Install php lib deps
13RUN apk update && apk upgrade
14RUN apk add --update libzip-dev \
15 zip \
16 unzip \
17 libpng-dev \
18 nginx \
19 supervisor \
20 git \
21 curl \
22 shadow \
23 composer \
24 yarn && rm -rf /var/cache/apk/*
25
26RUN usermod -u 1000 www-data
27RUN usermod -d /var/www www-data
28
29RUN mkdir -p /run/nginx && chown www-data:www-data /run/nginx
30
31ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.9/supercronic-linux-amd64 \
32 SUPERCRONIC=supercronic-linux-amd64 \
33 SUPERCRONIC_SHA1SUM=5ddf8ea26b56d4a7ff6faecdd8966610d5cb9d85
34
35RUN curl -fsSLO "$SUPERCRONIC_URL" \
36 && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
37 && chmod +x "$SUPERCRONIC" \
38 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
39 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
40
41# Install and enable php extensions
42RUN docker-php-ext-install sockets mysqli pdo_mysql zip gd bcmath > /dev/null
43
44ARG ENV="development"
45# Xdebug install
46RUN if [ $ENV = "development" ] ; then \
47 apk add --no-cache $PHPIZE_DEPS; \
48 pecl install xdebug > /dev/null; \
49 docker-php-ext-enable xdebug; \
50 echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
51 echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
52 echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
53 echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
54 fi ;
55
56# Setup working directory
57RUN chown -R www-data:www-data /var/www
58WORKDIR /var/www
59USER www-data
60
61
62# Install dependencies
63#RUN if [ $ENV = "development" ] ; then \
64## composer install -n; \
65# else \
66## composer install -n --no-dev; \
67# fi ;
68
69# Generate doctrine proxies
70
ANSWER
Answered 2021-Dec-23 at 11:20Huh. This surprised me a bit.
composer is correctly reporting the PHP version it's using. The problem is that it's not using the "correct" PHP interpreter.
The issue arises because of how you are installing composer.
Apparently by doing apk add composer
another version of PHP gets installed (you can find it on /usr/bin/php8
, this is the one on version 8.0.14).
Instead of letting apk
install composer for you, you can do it manually. There is nothing much to install it in any case, no need to go through the package manager. Particularly since PHP has not been installed via the package manager on your base image.
I've just removed the line containing composer
from the apk add --update
command, and added this somewhere below:
1Root composer.json requires php ^8.1 but your php version (8.0.14) does not satisfy that requirement.
2which php # returns only /usr/local/bin/php
3/usr/local/bin/php -v # returns PHP 8.1.1 (cli) (built: Dec 18 2021 01:38:53) (NTS)
4composer check-platform-reqs | grep php
5# returns:
6# ...
7# php 8.0.14 project/name requires php (^8.1) failed
8FROM php:8.1.1-fpm-alpine3.15
9
10ENV TZ=Europe/London
11
12# Install php lib deps
13RUN apk update && apk upgrade
14RUN apk add --update libzip-dev \
15 zip \
16 unzip \
17 libpng-dev \
18 nginx \
19 supervisor \
20 git \
21 curl \
22 shadow \
23 composer \
24 yarn && rm -rf /var/cache/apk/*
25
26RUN usermod -u 1000 www-data
27RUN usermod -d /var/www www-data
28
29RUN mkdir -p /run/nginx && chown www-data:www-data /run/nginx
30
31ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.9/supercronic-linux-amd64 \
32 SUPERCRONIC=supercronic-linux-amd64 \
33 SUPERCRONIC_SHA1SUM=5ddf8ea26b56d4a7ff6faecdd8966610d5cb9d85
34
35RUN curl -fsSLO "$SUPERCRONIC_URL" \
36 && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
37 && chmod +x "$SUPERCRONIC" \
38 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
39 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
40
41# Install and enable php extensions
42RUN docker-php-ext-install sockets mysqli pdo_mysql zip gd bcmath > /dev/null
43
44ARG ENV="development"
45# Xdebug install
46RUN if [ $ENV = "development" ] ; then \
47 apk add --no-cache $PHPIZE_DEPS; \
48 pecl install xdebug > /dev/null; \
49 docker-php-ext-enable xdebug; \
50 echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
51 echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
52 echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
53 echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
54 fi ;
55
56# Setup working directory
57RUN chown -R www-data:www-data /var/www
58WORKDIR /var/www
59USER www-data
60
61
62# Install dependencies
63#RUN if [ $ENV = "development" ] ; then \
64## composer install -n; \
65# else \
66## composer install -n --no-dev; \
67# fi ;
68
69# Generate doctrine proxies
70 RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
71 php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
72 php composer-setup.php && \
73 php -r "unlink('composer-setup.php');" && \
74 mv composer.phar /usr/local/bin/composer;
75
You could also simply download the latest composer PHAR file from here, and add it to the image, depending on how you want to go.
Now there is a single PHP version, and composer will run correctly on PHP 8.1.1.
QUESTION
Android Instrumented tests with KodeIn
Asked 2021-Nov-30 at 16:26We have an Android app that is using compose for the view layer and we are using Kodein for all of our dependency injections.
I have a BaseApplication class which is DIAware:
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6
I also have a MainActivity and a nav graph to manage navigation between the various composables.
Problem: How can I properly override these modules in my instrumented tests for MainActivity?
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6@RunWith(AndroidJUnit4::class)
7class MainActivityTest {
8 @get:Rule
9 val composeTestRule = createAndroidComposeRule<MainActivity>()
10
11 val moduleOverrides = DI.Module(allowSilentOverride = true) {
12 // add bindings for fakes w/ allowOverride = true
13 }
14
15 @Before
16 fun setup() {
17 val application =
18 ApplicationProvider.getApplicationContext() as BaseApplication
19
20 // how can I override the BaseApplication modules for my test?
21 }
22
23}
24
I cant seem to find any clear language on the matter and feel like I am missing something very obvious. Any help would be very much appreciated.
ANSWER
Answered 2021-Nov-30 at 16:26There are several ways to achieve that. The general approach is to override the actual modules like
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6@RunWith(AndroidJUnit4::class)
7class MainActivityTest {
8 @get:Rule
9 val composeTestRule = createAndroidComposeRule<MainActivity>()
10
11 val moduleOverrides = DI.Module(allowSilentOverride = true) {
12 // add bindings for fakes w/ allowOverride = true
13 }
14
15 @Before
16 fun setup() {
17 val application =
18 ApplicationProvider.getApplicationContext() as BaseApplication
19
20 // how can I override the BaseApplication modules for my test?
21 }
22
23}
24val someParrentKodeinModule...
25
26val mockModule = Kodein {
27 extend(someParrentKodeinModule, allowOverride = true)
28 bind<Foo>(overrides = true) with provider { Foo2() }
29}
30
31or
32
33val kodein = Kodein {
34 /* ... */
35 import(testsModule, allowOverride = true)
36}
37
where testsModule
is some module that already defines all the needed mock components that will be overridden in the main one.
Your approach is also good. The key point is to replace your DI with the needed one - this can be done making the DI in your app - var
instead of val
and assigning new value to it. But you will have to drop DIAware
1class BaseApplication : Application(), DIAware {
2 override val di: DI = DI.lazy {
3 import(modules) // modules defined in respective packages
4 }
5}
6@RunWith(AndroidJUnit4::class)
7class MainActivityTest {
8 @get:Rule
9 val composeTestRule = createAndroidComposeRule<MainActivity>()
10
11 val moduleOverrides = DI.Module(allowSilentOverride = true) {
12 // add bindings for fakes w/ allowOverride = true
13 }
14
15 @Before
16 fun setup() {
17 val application =
18 ApplicationProvider.getApplicationContext() as BaseApplication
19
20 // how can I override the BaseApplication modules for my test?
21 }
22
23}
24val someParrentKodeinModule...
25
26val mockModule = Kodein {
27 extend(someParrentKodeinModule, allowOverride = true)
28 bind<Foo>(overrides = true) with provider { Foo2() }
29}
30
31or
32
33val kodein = Kodein {
34 /* ... */
35 import(testsModule, allowOverride = true)
36}
37class BaseApplication : Application() {
38 var di: DI = DI.lazy {
39 import(modules) // modules defined in respective packages
40 }
41}
42
43@Before
44 fun setup() {
45 val application =
46 ApplicationProvider.getApplicationContext() as BaseApplication
47
48 application.di = moduleOverrides
49 }
50
51
Something like that.
And generally using single DI for the app inside the App class is not recommended. Use specialized modules for each component of the app you want to test
QUESTION
How to use .svg file in Jetpack Compose for Desktop?
Asked 2021-Nov-26 at 00:45I am trying to use a .svg
(vector file) to show an image but I am stuck and not able to do it. Is there any way I can use it, I tried to use it like this
1Image(imageFromResource("svg_file_name.svg"),contentDescription="")
2
But it throws an error :
1Image(imageFromResource("svg_file_name.svg"),contentDescription="")
2Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Failed to Image::makeFromEncoded
3 at org.jetbrains.skija.Image.makeFromEncoded(Image.java:130)
4 at androidx.compose.ui.graphics.DesktopImageAsset_desktopKt.imageFromResource(DesktopImageAsset.desktop.kt:77)
5 at ComposableSingletons$MainKt$lambda-1$1.invoke(main.kt:103)
6 at ComposableSingletons$MainKt$lambda-1$1.invoke(main.kt:98)
7 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
8 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
9 at androidx.compose.material.SurfaceKt$Surface$6.invoke(Surface.kt:267)
10 at androidx.compose.material.SurfaceKt$Surface$6.invoke(Surface.kt:254)
11 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
12 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
13 at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
14 at androidx.compose.material.SurfaceKt.Surface-F-jzlyU(Surface.kt:251)
15 at androidx.compose.material.SurfaceKt.Surface-F-jzlyU(Surface.kt:110)
16 at androidx.compose.material.CardKt.Card-F-jzlyU(Card.kt:66)
17 at MainKt.ShowCanvasIsEmpty(main.kt:93)
18 at MainKt.DisplayMainUI(main.kt:78)
19 at MainKt$main$1$1.invoke(main.kt:60)
20 at MainKt$main$1$1.invoke(main.kt:55)
21 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
22 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
23 at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
24 at androidx.compose.material.TextKt.ProvideTextStyle(Text.kt:252)
25 at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:81)
26 at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:80)
27 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
28 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
29 at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
30 at androidx.compose.material.MaterialThemeKt.MaterialTheme(MaterialTheme.kt:72)
31 at MainKt$main$1.invoke(main.kt:55)
32 at MainKt$main$1.invoke(main.kt:53)
33 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
34 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
35 at androidx.compose.desktop.AppWindow_desktopKt$Window$1$1.invoke(AppWindow.desktop.kt:97)
36 at androidx.compose.desktop.AppWindow_desktopKt$Window$1$1.invoke(AppWindow.desktop.kt:96)
37 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
38 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
39 at androidx.compose.desktop.AppWindow$show$1.invoke(AppWindow.desktop.kt:446)
40 at androidx.compose.desktop.AppWindow$show$1.invoke(AppWindow.desktop.kt:444)
41 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
42 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
43 at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
44 at androidx.compose.desktop.AppWindow$onCreate$1.invoke(AppWindow.desktop.kt:420)
45 at androidx.compose.desktop.AppWindow$onCreate$1.invoke(AppWindow.desktop.kt:419)
46 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
47 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
48 at androidx.compose.desktop.ComposeWindow$setContent$1$1.invoke(ComposeWindow.desktop.kt:95)
49 at androidx.compose.desktop.ComposeWindow$setContent$1$1.invoke(ComposeWindow.desktop.kt:94)
50 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
51 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
52 at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
53 at androidx.compose.desktop.ComposeWindow$setContent$1.invoke(ComposeWindow.desktop.kt:91)
54 at androidx.compose.desktop.ComposeWindow$setContent$1.invoke(ComposeWindow.desktop.kt:90)
55 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
56 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
57 at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
58 at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:148)
59 at androidx.compose.ui.platform.Wrapper_desktopKt$ProvideDesktopCompositionsLocals$1.invoke(Wrapper.desktop.kt:51)
60 at androidx.compose.ui.platform.Wrapper_desktopKt$ProvideDesktopCompositionsLocals$1.invoke(Wrapper.desktop.kt:50)
61 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
62 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
63 at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
64 at androidx.compose.ui.platform.Wrapper_desktopKt.ProvideDesktopCompositionsLocals(Wrapper.desktop.kt:48)
65 at androidx.compose.ui.platform.Wrapper_desktopKt.access$ProvideDesktopCompositionsLocals(Wrapper.desktop.kt:1)
66 at androidx.compose.ui.platform.Wrapper_desktopKt$setContent$1.invoke(Wrapper.desktop.kt:40)
67 at androidx.compose.ui.platform.Wrapper_desktopKt$setContent$1.invoke(Wrapper.desktop.kt:39)
68 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
69 at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
70 at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:3324)
71 at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2575)
72 at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2571)
73 at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(SnapshotState.kt:523)
74 at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2564)
75 at androidx.compose.runtime.ComposerImpl.composeContent$runtime(Composer.kt:2515)
76 at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:476)
77 at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:727)
78 at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:432)
79 at androidx.compose.ui.platform.Wrapper_desktopKt.setContent(Wrapper.desktop.kt:39)
80 at androidx.compose.desktop.ComposeLayer.initOwner(ComposeLayer.desktop.kt:268)
81 at androidx.compose.desktop.ComposeLayer.access$initOwner(ComposeLayer.desktop.kt:49)
82 at androidx.compose.desktop.ComposeLayer$Wrapped.init(ComposeLayer.desktop.kt:87)
83 at org.jetbrains.skiko.SkiaLayer.checkInit(SkiaLayer.kt:69)
84 at org.jetbrains.skiko.SkiaLayer.access$checkInit(SkiaLayer.kt:23)
85 at org.jetbrains.skiko.SkiaLayer$2.hierarchyChanged(SkiaLayer.kt:57)
86 at java.desktop/java.awt.Component.processHierarchyEvent(Component.java:6819)
87 at java.desktop/java.awt.Component.processEvent(Component.java:6438)
88 at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027)
89 at java.desktop/java.awt.Component.dispatchEvent(Component.java:4859)
90 at java.desktop/java.awt.Component.addNotify(Component.java:7123)
91 at java.desktop/java.awt.Canvas.addNotify(Canvas.java:104)
92 at java.desktop/java.awt.Container.addNotify(Container.java:2800)
93 at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
94 at java.desktop/java.awt.Container.addNotify(Container.java:2800)
95 at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
96 at java.desktop/java.awt.Container.addNotify(Container.java:2800)
97 at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
98 at java.desktop/java.awt.Container.addNotify(Container.java:2800)
99 at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
100 at java.desktop/java.awt.Container.addNotify(Container.java:2800)
101 at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4791)
102 at java.desktop/javax.swing.JRootPane.addNotify(JRootPane.java:733)
103 at java.desktop/java.awt.Container.addNotify(Container.java:2800)
104 at java.desktop/java.awt.Window.addNotify(Window.java:787)
105 at java.desktop/java.awt.Frame.addNotify(Frame.java:490)
106 at java.desktop/java.awt.Window.show(Window.java:1049)
107 at java.desktop/java.awt.Component.show(Component.java:1732)
108 at java.desktop/java.awt.Component.setVisible(Component.java:1679)
109 at java.desktop/java.awt.Window.setVisible(Window.java:1032)
110 at androidx.compose.desktop.ComposeWindow.setVisible(ComposeWindow.desktop.kt:110)
111 at androidx.compose.desktop.AppWindow.show(AppWindow.desktop.kt:449)
112 at androidx.compose.desktop.AppWindow.show$default(AppWindow.desktop.kt:435)
113 at androidx.compose.desktop.AppWindow_desktopKt$Window$1.run(AppWindow.desktop.kt:96)
114 at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
115 at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
116 at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
117 at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
118 at java.base/java.security.AccessController.doPrivileged(Native Method)
119 at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
120 at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
121 at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
122 at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
123 at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
124 at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
125 at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
126 at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
127
ANSWER
Answered 2021-Nov-26 at 00:45Desktop Compose has painterResource
, which supports:
- SVG
- XML vector drawable
- raster formats (BMP, GIF, HEIF, ICO, JPEG, PNG, WBMP, WebP)
To load an image from other places (file storage, database, network), use these functions inside LaunchedEffect
or remember
: loadSvgPainter
, loadXmlImageVector
, loadImageBitmap
QUESTION
Keeps giving Undefined variable error in routing framework code
Asked 2021-Nov-17 at 09:53I need to make a simple routing system.
I need to redirect when i type the url localhost/user/login
it need to go to the UserController file, and also exactly the same with just when you type localhost
it needs to go to the HomeController.
- Check whether the requested controller exists and if so, 'include' it.
- Check if the requested method exists, and if so, call it.
- Include only the controller that is important for that URL
- If the controller does not exist, print a 404 Not found message.
- If the method does not exist, print a 404 Not found message.
- Also return a 404 status code for 404 pages.
It keeps giving an error with undefining a variable, and when I /
to a page it keeps giving an undefined variable error.
When change the $_server
to $_SERVER
it doesn't work at all. This is the error it gives when using $_server
:
Notice: Undefined variable: _server in C:\xampp\htdocs\src\index.php on line 2
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\src\index.php on line 2
Notice: Undefined offset: 1 in C:\xampp\htdocs\src\index.php on line 3
Down here are the files I use.
1<?php
2$linkExplode = explode("/", $_SERVER['REQUEST_URI']);
3
4if (empty($linkExplode[1] && empty($linkExplode[2]))) {
5 $linkExplode[1] = 'Home';
6 $linkExplode[2] = 'index';
7}
8
9$controller = empty($linkExplode[1]) ? 'home' : $linkExplode[1];
10$method = empty($linkExplode[2]) ? 'index' : $linkExplode[2];
11
12if (file_exists('./Controllers/' . ucfirst($controller) . 'Homecontroller.class.php')) {
13 require('./Controllers/' . ucfirst($controller) . 'UserController.class.php');
14 $classname = ucfirst($controller) . 'Controller';
15 $class = new $classname();
16
17 if (method_exists($class, $method)) {
18 $class->$method();
19 } else {
20 http_response_code(404);
21 die;
22 }
23} else {
24 http_response_code(404);
25 die;
26}
27
HomeController
1<?php
2$linkExplode = explode("/", $_SERVER['REQUEST_URI']);
3
4if (empty($linkExplode[1] && empty($linkExplode[2]))) {
5 $linkExplode[1] = 'Home';
6 $linkExplode[2] = 'index';
7}
8
9$controller = empty($linkExplode[1]) ? 'home' : $linkExplode[1];
10$method = empty($linkExplode[2]) ? 'index' : $linkExplode[2];
11
12if (file_exists('./Controllers/' . ucfirst($controller) . 'Homecontroller.class.php')) {
13 require('./Controllers/' . ucfirst($controller) . 'UserController.class.php');
14 $classname = ucfirst($controller) . 'Controller';
15 $class = new $classname();
16
17 if (method_exists($class, $method)) {
18 $class->$method();
19 } else {
20 http_response_code(404);
21 die;
22 }
23} else {
24 http_response_code(404);
25 die;
26}
27<?php
28class HomeController
29{
30 public function index()
31 {
32 echo 'De home pagina!';
33 }
34}
35
UserController
1<?php
2$linkExplode = explode("/", $_SERVER['REQUEST_URI']);
3
4if (empty($linkExplode[1] && empty($linkExplode[2]))) {
5 $linkExplode[1] = 'Home';
6 $linkExplode[2] = 'index';
7}
8
9$controller = empty($linkExplode[1]) ? 'home' : $linkExplode[1];
10$method = empty($linkExplode[2]) ? 'index' : $linkExplode[2];
11
12if (file_exists('./Controllers/' . ucfirst($controller) . 'Homecontroller.class.php')) {
13 require('./Controllers/' . ucfirst($controller) . 'UserController.class.php');
14 $classname = ucfirst($controller) . 'Controller';
15 $class = new $classname();
16
17 if (method_exists($class, $method)) {
18 $class->$method();
19 } else {
20 http_response_code(404);
21 die;
22 }
23} else {
24 http_response_code(404);
25 die;
26}
27<?php
28class HomeController
29{
30 public function index()
31 {
32 echo 'De home pagina!';
33 }
34}
35<?php
36class UserController
37{
38 public function login()
39 {
40 echo 'De login pagina!';
41 }
42}
43
Htacces
1<?php
2$linkExplode = explode("/", $_SERVER['REQUEST_URI']);
3
4if (empty($linkExplode[1] && empty($linkExplode[2]))) {
5 $linkExplode[1] = 'Home';
6 $linkExplode[2] = 'index';
7}
8
9$controller = empty($linkExplode[1]) ? 'home' : $linkExplode[1];
10$method = empty($linkExplode[2]) ? 'index' : $linkExplode[2];
11
12if (file_exists('./Controllers/' . ucfirst($controller) . 'Homecontroller.class.php')) {
13 require('./Controllers/' . ucfirst($controller) . 'UserController.class.php');
14 $classname = ucfirst($controller) . 'Controller';
15 $class = new $classname();
16
17 if (method_exists($class, $method)) {
18 $class->$method();
19 } else {
20 http_response_code(404);
21 die;
22 }
23} else {
24 http_response_code(404);
25 die;
26}
27<?php
28class HomeController
29{
30 public function index()
31 {
32 echo 'De home pagina!';
33 }
34}
35<?php
36class UserController
37{
38 public function login()
39 {
40 echo 'De login pagina!';
41 }
42}
43RewriteEngine On
44
45RewriteCond %{REQUEST_FILENAME} !-d
46RewriteCond %{REQUEST_FILENAME} !-f
47RewriteCond %{REQUEST_FILENAME} !-l
48
49RewriteRule ^(.+)$ src/index.php?url=$1 [QSA,L]
50DirectoryIndex src/index.php
51
Currently Var_Dumping $_SERVER Giving this back
1<?php
2$linkExplode = explode("/", $_SERVER['REQUEST_URI']);
3
4if (empty($linkExplode[1] && empty($linkExplode[2]))) {
5 $linkExplode[1] = 'Home';
6 $linkExplode[2] = 'index';
7}
8
9$controller = empty($linkExplode[1]) ? 'home' : $linkExplode[1];
10$method = empty($linkExplode[2]) ? 'index' : $linkExplode[2];
11
12if (file_exists('./Controllers/' . ucfirst($controller) . 'Homecontroller.class.php')) {
13 require('./Controllers/' . ucfirst($controller) . 'UserController.class.php');
14 $classname = ucfirst($controller) . 'Controller';
15 $class = new $classname();
16
17 if (method_exists($class, $method)) {
18 $class->$method();
19 } else {
20 http_response_code(404);
21 die;
22 }
23} else {
24 http_response_code(404);
25 die;
26}
27<?php
28class HomeController
29{
30 public function index()
31 {
32 echo 'De home pagina!';
33 }
34}
35<?php
36class UserController
37{
38 public function login()
39 {
40 echo 'De login pagina!';
41 }
42}
43RewriteEngine On
44
45RewriteCond %{REQUEST_FILENAME} !-d
46RewriteCond %{REQUEST_FILENAME} !-f
47RewriteCond %{REQUEST_FILENAME} !-l
48
49RewriteRule ^(.+)$ src/index.php?url=$1 [QSA,L]
50DirectoryIndex src/index.php
51array(58) { ["REDIRECT_MIBDIRS"]=> string(24) "C:/xampp/php/extras/mibs" ["REDIRECT_MYSQL_HOME"]=> string(16) "\xampp\mysql\bin" ["REDIRECT_OPENSSL_CONF"]=> string(31) "C:/xampp/apache/bin/openssl.cnf" ["REDIRECT_PHP_PEAR_SYSCONF_DIR"]=> string(10) "\xampp\php" ["REDIRECT_PHPRC"]=> string(10) "\xampp\php" ["REDIRECT_TMP"]=> string(10) "\xampp\tmp" ["REDIRECT_STATUS"]=> string(3) "200" ["MIBDIRS"]=> string(24) "C:/xampp/php/extras/mibs" ["MYSQL_HOME"]=> string(16) "\xampp\mysql\bin" ["OPENSSL_CONF"]=> string(31) "C:/xampp/apache/bin/openssl.cnf" ["PHP_PEAR_SYSCONF_DIR"]=> string(10) "\xampp\php" ["PHPRC"]=> string(10) "\xampp\php" ["TMP"]=> string(10) "\xampp\tmp" ["HTTP_HOST"]=> string(9) "localhost" ["HTTP_CONNECTION"]=> string(10) "keep-alive" ["HTTP_CACHE_CONTROL"]=> string(9) "max-age=0" ["HTTP_SEC_CH_UA"]=> string(64) ""Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"" ["HTTP_SEC_CH_UA_MOBILE"]=> string(2) "?0" ["HTTP_SEC_CH_UA_PLATFORM"]=> string(9) ""Windows"" ["HTTP_UPGRADE_INSECURE_REQUESTS"]=> string(1) "1" ["HTTP_USER_AGENT"]=> string(114) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" ["HTTP_ACCEPT"]=> string(135) "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ["HTTP_SEC_FETCH_SITE"]=> string(10) "cross-site" ["HTTP_SEC_FETCH_MODE"]=> string(8) "navigate" ["HTTP_SEC_FETCH_USER"]=> string(2) "?1" ["HTTP_SEC_FETCH_DEST"]=> string(8) "document" ["HTTP_ACCEPT_ENCODING"]=> string(17) "gzip, deflate, br" ["HTTP_ACCEPT_LANGUAGE"]=> string(35) "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7" ["HTTP_COOKIE"]=> string(36) "PHPSESSID=auct5lh5cga85hmln0o54kfjf4" ["PATH"]=> string(964) "C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\jeann\AppData\Local\Android\Sdk\emulator;C:\ProgramData\ComposerSetup\bin;C:\Users\jeann\AppData\Local\Microsoft\WindowsApps;C:\Users\jeann\AppData\Local\Programs\Microsoft VS Code\bin;C:\PHP;C:\MinGW\bin;C:\Users\jeann\AppData\Roaming\npm;C:\Users\jeann\Pictures\gradle-7.1.1\bin;C:\Users\jeann\AppData\Local\Android\Sdk\emulator;C:\Users\jeann\AppData\Local\Android\Sdk\tools;C:\Users\jeann\AppData\Local\Android\Sdk\platform-tools;C:\Users\jeann\AppData\Roaming\Composer\vendor\bin" ["SystemRoot"]=> string(10) "C:\WINDOWS" ["COMSPEC"]=> string(27) "C:\WINDOWS\system32\cmd.exe" ["PATHEXT"]=> string(53) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" ["WINDIR"]=> string(10) "C:\WINDOWS" ["SERVER_SIGNATURE"]=> string(95) "
52Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11 Server at localhost Port 80
53" ["SERVER_SOFTWARE"]=> string(47) "Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11" ["SERVER_NAME"]=> string(9) "localhost" ["SERVER_ADDR"]=> string(3) "::1" ["SERVER_PORT"]=> string(2) "80" ["REMOTE_ADDR"]=> string(3) "::1" ["DOCUMENT_ROOT"]=> string(15) "C:/xampp/htdocs" ["REQUEST_SCHEME"]=> string(4) "http" ["CONTEXT_PREFIX"]=> string(0) "" ["CONTEXT_DOCUMENT_ROOT"]=> string(15) "C:/xampp/htdocs" ["SERVER_ADMIN"]=> string(20) "postmaster@localhost" ["SCRIPT_FILENAME"]=> string(29) "C:/xampp/htdocs/src/index.php" ["REMOTE_PORT"]=> string(5) "51472" ["REDIRECT_URL"]=> string(11) "/user/login" ["REDIRECT_QUERY_STRING"]=> string(14) "url=user/login" ["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["REQUEST_METHOD"]=> string(3) "GET" ["QUERY_STRING"]=> string(14) "url=user/login" ["REQUEST_URI"]=> string(11) "/user/login" ["SCRIPT_NAME"]=> string(14) "/src/index.php" ["PHP_SELF"]=> string(14) "/src/index.php" ["REQUEST_TIME_FLOAT"]=> float(1636987064.7515) ["REQUEST_TIME"]=> int(1636987064) }
54
ANSWER
Answered 2021-Nov-17 at 09:46First thing, is make sure you HTACCESS route works. If it does and brings you to the correct page then on to the next step.
Second step understanding your PHP code here, there are a couple contradictions and fixes you need.
1<?php
2$linkExplode = explode("/", $_SERVER['REQUEST_URI']);
3
4if (empty($linkExplode[1] && empty($linkExplode[2]))) {
5 $linkExplode[1] = 'Home';
6 $linkExplode[2] = 'index';
7}
8
9$controller = empty($linkExplode[1]) ? 'home' : $linkExplode[1];
10$method = empty($linkExplode[2]) ? 'index' : $linkExplode[2];
11
12if (file_exists('./Controllers/' . ucfirst($controller) . 'Homecontroller.class.php')) {
13 require('./Controllers/' . ucfirst($controller) . 'UserController.class.php');
14 $classname = ucfirst($controller) . 'Controller';
15 $class = new $classname();
16
17 if (method_exists($class, $method)) {
18 $class->$method();
19 } else {
20 http_response_code(404);
21 die;
22 }
23} else {
24 http_response_code(404);
25 die;
26}
27<?php
28class HomeController
29{
30 public function index()
31 {
32 echo 'De home pagina!';
33 }
34}
35<?php
36class UserController
37{
38 public function login()
39 {
40 echo 'De login pagina!';
41 }
42}
43RewriteEngine On
44
45RewriteCond %{REQUEST_FILENAME} !-d
46RewriteCond %{REQUEST_FILENAME} !-f
47RewriteCond %{REQUEST_FILENAME} !-l
48
49RewriteRule ^(.+)$ src/index.php?url=$1 [QSA,L]
50DirectoryIndex src/index.php
51array(58) { ["REDIRECT_MIBDIRS"]=> string(24) "C:/xampp/php/extras/mibs" ["REDIRECT_MYSQL_HOME"]=> string(16) "\xampp\mysql\bin" ["REDIRECT_OPENSSL_CONF"]=> string(31) "C:/xampp/apache/bin/openssl.cnf" ["REDIRECT_PHP_PEAR_SYSCONF_DIR"]=> string(10) "\xampp\php" ["REDIRECT_PHPRC"]=> string(10) "\xampp\php" ["REDIRECT_TMP"]=> string(10) "\xampp\tmp" ["REDIRECT_STATUS"]=> string(3) "200" ["MIBDIRS"]=> string(24) "C:/xampp/php/extras/mibs" ["MYSQL_HOME"]=> string(16) "\xampp\mysql\bin" ["OPENSSL_CONF"]=> string(31) "C:/xampp/apache/bin/openssl.cnf" ["PHP_PEAR_SYSCONF_DIR"]=> string(10) "\xampp\php" ["PHPRC"]=> string(10) "\xampp\php" ["TMP"]=> string(10) "\xampp\tmp" ["HTTP_HOST"]=> string(9) "localhost" ["HTTP_CONNECTION"]=> string(10) "keep-alive" ["HTTP_CACHE_CONTROL"]=> string(9) "max-age=0" ["HTTP_SEC_CH_UA"]=> string(64) ""Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"" ["HTTP_SEC_CH_UA_MOBILE"]=> string(2) "?0" ["HTTP_SEC_CH_UA_PLATFORM"]=> string(9) ""Windows"" ["HTTP_UPGRADE_INSECURE_REQUESTS"]=> string(1) "1" ["HTTP_USER_AGENT"]=> string(114) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" ["HTTP_ACCEPT"]=> string(135) "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ["HTTP_SEC_FETCH_SITE"]=> string(10) "cross-site" ["HTTP_SEC_FETCH_MODE"]=> string(8) "navigate" ["HTTP_SEC_FETCH_USER"]=> string(2) "?1" ["HTTP_SEC_FETCH_DEST"]=> string(8) "document" ["HTTP_ACCEPT_ENCODING"]=> string(17) "gzip, deflate, br" ["HTTP_ACCEPT_LANGUAGE"]=> string(35) "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7" ["HTTP_COOKIE"]=> string(36) "PHPSESSID=auct5lh5cga85hmln0o54kfjf4" ["PATH"]=> string(964) "C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\jeann\AppData\Local\Android\Sdk\emulator;C:\ProgramData\ComposerSetup\bin;C:\Users\jeann\AppData\Local\Microsoft\WindowsApps;C:\Users\jeann\AppData\Local\Programs\Microsoft VS Code\bin;C:\PHP;C:\MinGW\bin;C:\Users\jeann\AppData\Roaming\npm;C:\Users\jeann\Pictures\gradle-7.1.1\bin;C:\Users\jeann\AppData\Local\Android\Sdk\emulator;C:\Users\jeann\AppData\Local\Android\Sdk\tools;C:\Users\jeann\AppData\Local\Android\Sdk\platform-tools;C:\Users\jeann\AppData\Roaming\Composer\vendor\bin" ["SystemRoot"]=> string(10) "C:\WINDOWS" ["COMSPEC"]=> string(27) "C:\WINDOWS\system32\cmd.exe" ["PATHEXT"]=> string(53) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC" ["WINDIR"]=> string(10) "C:\WINDOWS" ["SERVER_SIGNATURE"]=> string(95) "
52Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11 Server at localhost Port 80
53" ["SERVER_SOFTWARE"]=> string(47) "Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11" ["SERVER_NAME"]=> string(9) "localhost" ["SERVER_ADDR"]=> string(3) "::1" ["SERVER_PORT"]=> string(2) "80" ["REMOTE_ADDR"]=> string(3) "::1" ["DOCUMENT_ROOT"]=> string(15) "C:/xampp/htdocs" ["REQUEST_SCHEME"]=> string(4) "http" ["CONTEXT_PREFIX"]=> string(0) "" ["CONTEXT_DOCUMENT_ROOT"]=> string(15) "C:/xampp/htdocs" ["SERVER_ADMIN"]=> string(20) "postmaster@localhost" ["SCRIPT_FILENAME"]=> string(29) "C:/xampp/htdocs/src/index.php" ["REMOTE_PORT"]=> string(5) "51472" ["REDIRECT_URL"]=> string(11) "/user/login" ["REDIRECT_QUERY_STRING"]=> string(14) "url=user/login" ["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["REQUEST_METHOD"]=> string(3) "GET" ["QUERY_STRING"]=> string(14) "url=user/login" ["REQUEST_URI"]=> string(11) "/user/login" ["SCRIPT_NAME"]=> string(14) "/src/index.php" ["PHP_SELF"]=> string(14) "/src/index.php" ["REQUEST_TIME_FLOAT"]=> float(1636987064.7515) ["REQUEST_TIME"]=> int(1636987064) }
54<?php
55$linkExplode = explode("/", $_SERVER['REQUEST_URI']);
56
57//YOU CAN REMOVE THIS WHOLE IF STATEMENT
58if (empty($linkExplode[1] && empty($linkExplode[2]))) {
59 $linkExplode[1] = 'Home';
60 $linkExplode[2] = 'index';
61}
62
63//You should check that the $linkExplode isset as well as not empty
64$controller = isset($linkExplode[1]) && !empty($linkExplode[1]) ? $linkExplode[1] : "Home";
65$method = isset($linkExplode[2]) && !empty($linkExplode[2]) ? $linkExplode[2] : "index";
66
67// Here we remove the 'hardcoded HOME and USER from the string 'Controller.class.php'
68// AND you also need to make sure that you require the same file your verifying is actually there.
69if (file_exists('./Controllers/' . ucfirst($controller) . 'Controller.class.php')) {
70 require('./Controllers/' . ucfirst($controller) . 'Controller.class.php');
71 $classname = ucfirst($controller) . 'Controller';
72 $class = new $classname();
73
74 if (method_exists($class, $method)) {
75 $class->$method();
76 } else {
77 http_response_code(404);
78 die;
79 }
80} else {
81 http_response_code(404);
82 die;
83}
84
QUESTION
Can't install bash in multiarch build on Alpine
Asked 2021-Nov-16 at 11:01I am trying to build image for linux/arm64/v8
on linux/amd64
Gitlab runner. I run it with this command:
1docker buildx create --use
2docker buildx build --platform linux/arm64/v8 -f Dockerfile.dev -t registry.gitlab.com/xxx:yyy --build-arg ENV=dev --build-arg COMPOSER_AUTH_FILE=./auth.json .
3
My Dockerfile is fairly simple:
1docker buildx create --use
2docker buildx build --platform linux/arm64/v8 -f Dockerfile.dev -t registry.gitlab.com/xxx:yyy --build-arg ENV=dev --build-arg COMPOSER_AUTH_FILE=./auth.json .
3FROM alpine:latest
4
5RUN apk update && \
6 apk add --no-cache composer git bash openssh-client patch && \
7 apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
8
But it fails with:
1docker buildx create --use
2docker buildx build --platform linux/arm64/v8 -f Dockerfile.dev -t registry.gitlab.com/xxx:yyy --build-arg ENV=dev --build-arg COMPOSER_AUTH_FILE=./auth.json .
3FROM alpine:latest
4
5RUN apk update && \
6 apk add --no-cache composer git bash openssh-client patch && \
7 apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
8#6 [2/2] RUN apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
9#6 0.185 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
10#6 0.832 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
11#6 1.679 v3.14.2-119-g9c4e1aa60c [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
12#6 1.679 v3.14.2-120-g90167408c8 [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
13#6 1.679 OK: 14818 distinct packages available
14#6 1.828 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
15#6 2.263 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
16#6 2.977 (1/31) Installing ncurses-terminfo-base (6.2_p20210612-r0)
17#6 3.010 (2/31) Installing ncurses-libs (6.2_p20210612-r0)
18#6 3.049 (3/31) Installing readline (8.1.0-r0)
19#6 3.075 (4/31) Installing bash (5.1.4-r0)
20#6 3.137 Executing bash-5.1.4-r0.post-install
21#6 3.144 ERROR: bash-5.1.4-r0.post-install: script exited with error 1
22#6 3.144 (5/31) Installing php7-common (7.4.25-r0)
23#6 3.159 (6/31) Installing argon2-libs (20190702-r1)
24#6 3.171 (7/31) Installing libedit (20210216.3.1-r0)
25#6 3.190 (8/31) Installing pcre2 (10.36-r0)
26#6 3.225 (9/31) Installing xz-libs (5.2.5-r0)
27#6 3.244 (10/31) Installing libxml2 (2.9.12-r1)
28#6 3.308 (11/31) Installing php7 (7.4.25-r0)
29#6 3.503 (12/31) Installing php7-phar (7.4.25-r0)
30#6 3.527 (13/31) Installing ca-certificates (20191127-r5)
31#6 3.575 (14/31) Installing brotli-libs (1.0.9-r5)
32#6 3.620 (15/31) Installing nghttp2-libs (1.43.0-r0)
33#6 3.638 (16/31) Installing libcurl (7.79.1-r0)
34#6 3.674 (17/31) Installing php7-curl (7.4.25-r0)
35#6 3.690 (18/31) Installing php7-iconv (7.4.25-r0)
36#6 3.702 (19/31) Installing php7-json (7.4.25-r0)
37#6 3.716 (20/31) Installing oniguruma (6.9.7.1-r0)
38#6 3.747 (21/31) Installing php7-mbstring (7.4.25-r0)
39#6 3.815 (22/31) Installing php7-openssl (7.4.25-r0)
40#6 3.833 (23/31) Installing libzip (1.7.3-r2)
41#6 3.849 (24/31) Installing php7-zip (7.4.25-r0)
42#6 3.863 (25/31) Installing composer (2.1.9-r0)
43#6 3.939 (26/31) Installing expat (2.4.1-r0)
44#6 3.958 (27/31) Installing git (2.32.0-r0)
45#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
46#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
47#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
48#6 4.727 (31/31) Installing patch (2.7.6-r7)
49#6 4.749 Executing busybox-1.33.1-r3.trigger
50#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
51#6 4.754 Executing ca-certificates-20191127-r5.trigger
52#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
53#6 4.765 1 error; 36 MiB in 45 packages
54#6 ERROR: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
55------
56 > [2/2] RUN apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev:
57#6 3.958 (27/31) Installing git (2.32.0-r0)
58#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
59#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
60#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
61#6 4.727 (31/31) Installing patch (2.7.6-r7)
62#6 4.749 Executing busybox-1.33.1-r3.trigger
63#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
64#6 4.754 Executing ca-certificates-20191127-r5.trigger
65#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
66#6 4.765 1 error; 36 MiB in 45 packages
67------
68Dockerfile.dev:3
69--------------------
70 2 |
71 3 | >>> RUN apk update && \
72 4 | >>> apk add --no-cache composer git bash openssh-client patch && \
73 5 | >>> apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
74 6 |
75--------------------
76error: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
77make: *** [Makefile:18: feature] Error 1
78Cleaning up file based variables
7900:01
80ERROR: Job failed: exit code 2
81
It's Gitlab runner version 13.4.1
and Docker executor docker:stable
. What can I do about this issue?
ANSWER
Answered 2021-Nov-16 at 11:01There were three problems with my approach:
- I needed to install buildx extension
1docker buildx create --use
2docker buildx build --platform linux/arm64/v8 -f Dockerfile.dev -t registry.gitlab.com/xxx:yyy --build-arg ENV=dev --build-arg COMPOSER_AUTH_FILE=./auth.json .
3FROM alpine:latest
4
5RUN apk update && \
6 apk add --no-cache composer git bash openssh-client patch && \
7 apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
8#6 [2/2] RUN apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
9#6 0.185 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
10#6 0.832 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
11#6 1.679 v3.14.2-119-g9c4e1aa60c [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
12#6 1.679 v3.14.2-120-g90167408c8 [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
13#6 1.679 OK: 14818 distinct packages available
14#6 1.828 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
15#6 2.263 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
16#6 2.977 (1/31) Installing ncurses-terminfo-base (6.2_p20210612-r0)
17#6 3.010 (2/31) Installing ncurses-libs (6.2_p20210612-r0)
18#6 3.049 (3/31) Installing readline (8.1.0-r0)
19#6 3.075 (4/31) Installing bash (5.1.4-r0)
20#6 3.137 Executing bash-5.1.4-r0.post-install
21#6 3.144 ERROR: bash-5.1.4-r0.post-install: script exited with error 1
22#6 3.144 (5/31) Installing php7-common (7.4.25-r0)
23#6 3.159 (6/31) Installing argon2-libs (20190702-r1)
24#6 3.171 (7/31) Installing libedit (20210216.3.1-r0)
25#6 3.190 (8/31) Installing pcre2 (10.36-r0)
26#6 3.225 (9/31) Installing xz-libs (5.2.5-r0)
27#6 3.244 (10/31) Installing libxml2 (2.9.12-r1)
28#6 3.308 (11/31) Installing php7 (7.4.25-r0)
29#6 3.503 (12/31) Installing php7-phar (7.4.25-r0)
30#6 3.527 (13/31) Installing ca-certificates (20191127-r5)
31#6 3.575 (14/31) Installing brotli-libs (1.0.9-r5)
32#6 3.620 (15/31) Installing nghttp2-libs (1.43.0-r0)
33#6 3.638 (16/31) Installing libcurl (7.79.1-r0)
34#6 3.674 (17/31) Installing php7-curl (7.4.25-r0)
35#6 3.690 (18/31) Installing php7-iconv (7.4.25-r0)
36#6 3.702 (19/31) Installing php7-json (7.4.25-r0)
37#6 3.716 (20/31) Installing oniguruma (6.9.7.1-r0)
38#6 3.747 (21/31) Installing php7-mbstring (7.4.25-r0)
39#6 3.815 (22/31) Installing php7-openssl (7.4.25-r0)
40#6 3.833 (23/31) Installing libzip (1.7.3-r2)
41#6 3.849 (24/31) Installing php7-zip (7.4.25-r0)
42#6 3.863 (25/31) Installing composer (2.1.9-r0)
43#6 3.939 (26/31) Installing expat (2.4.1-r0)
44#6 3.958 (27/31) Installing git (2.32.0-r0)
45#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
46#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
47#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
48#6 4.727 (31/31) Installing patch (2.7.6-r7)
49#6 4.749 Executing busybox-1.33.1-r3.trigger
50#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
51#6 4.754 Executing ca-certificates-20191127-r5.trigger
52#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
53#6 4.765 1 error; 36 MiB in 45 packages
54#6 ERROR: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
55------
56 > [2/2] RUN apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev:
57#6 3.958 (27/31) Installing git (2.32.0-r0)
58#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
59#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
60#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
61#6 4.727 (31/31) Installing patch (2.7.6-r7)
62#6 4.749 Executing busybox-1.33.1-r3.trigger
63#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
64#6 4.754 Executing ca-certificates-20191127-r5.trigger
65#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
66#6 4.765 1 error; 36 MiB in 45 packages
67------
68Dockerfile.dev:3
69--------------------
70 2 |
71 3 | >>> RUN apk update && \
72 4 | >>> apk add --no-cache composer git bash openssh-client patch && \
73 5 | >>> apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
74 6 |
75--------------------
76error: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
77make: *** [Makefile:18: feature] Error 1
78Cleaning up file based variables
7900:01
80ERROR: Job failed: exit code 2
81- mkdir -p ~/.docker/cli-plugins
82- wget -qO ~/.docker/cli-plugins/docker-buildx `wget -O - https://api.github.com/repos/docker/buildx/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4`
83- chmod a+x ~/.docker/cli-plugins/docker-buildx
84
- I had to install emulators through qemu
1docker buildx create --use
2docker buildx build --platform linux/arm64/v8 -f Dockerfile.dev -t registry.gitlab.com/xxx:yyy --build-arg ENV=dev --build-arg COMPOSER_AUTH_FILE=./auth.json .
3FROM alpine:latest
4
5RUN apk update && \
6 apk add --no-cache composer git bash openssh-client patch && \
7 apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
8#6 [2/2] RUN apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
9#6 0.185 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
10#6 0.832 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
11#6 1.679 v3.14.2-119-g9c4e1aa60c [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
12#6 1.679 v3.14.2-120-g90167408c8 [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
13#6 1.679 OK: 14818 distinct packages available
14#6 1.828 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
15#6 2.263 fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
16#6 2.977 (1/31) Installing ncurses-terminfo-base (6.2_p20210612-r0)
17#6 3.010 (2/31) Installing ncurses-libs (6.2_p20210612-r0)
18#6 3.049 (3/31) Installing readline (8.1.0-r0)
19#6 3.075 (4/31) Installing bash (5.1.4-r0)
20#6 3.137 Executing bash-5.1.4-r0.post-install
21#6 3.144 ERROR: bash-5.1.4-r0.post-install: script exited with error 1
22#6 3.144 (5/31) Installing php7-common (7.4.25-r0)
23#6 3.159 (6/31) Installing argon2-libs (20190702-r1)
24#6 3.171 (7/31) Installing libedit (20210216.3.1-r0)
25#6 3.190 (8/31) Installing pcre2 (10.36-r0)
26#6 3.225 (9/31) Installing xz-libs (5.2.5-r0)
27#6 3.244 (10/31) Installing libxml2 (2.9.12-r1)
28#6 3.308 (11/31) Installing php7 (7.4.25-r0)
29#6 3.503 (12/31) Installing php7-phar (7.4.25-r0)
30#6 3.527 (13/31) Installing ca-certificates (20191127-r5)
31#6 3.575 (14/31) Installing brotli-libs (1.0.9-r5)
32#6 3.620 (15/31) Installing nghttp2-libs (1.43.0-r0)
33#6 3.638 (16/31) Installing libcurl (7.79.1-r0)
34#6 3.674 (17/31) Installing php7-curl (7.4.25-r0)
35#6 3.690 (18/31) Installing php7-iconv (7.4.25-r0)
36#6 3.702 (19/31) Installing php7-json (7.4.25-r0)
37#6 3.716 (20/31) Installing oniguruma (6.9.7.1-r0)
38#6 3.747 (21/31) Installing php7-mbstring (7.4.25-r0)
39#6 3.815 (22/31) Installing php7-openssl (7.4.25-r0)
40#6 3.833 (23/31) Installing libzip (1.7.3-r2)
41#6 3.849 (24/31) Installing php7-zip (7.4.25-r0)
42#6 3.863 (25/31) Installing composer (2.1.9-r0)
43#6 3.939 (26/31) Installing expat (2.4.1-r0)
44#6 3.958 (27/31) Installing git (2.32.0-r0)
45#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
46#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
47#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
48#6 4.727 (31/31) Installing patch (2.7.6-r7)
49#6 4.749 Executing busybox-1.33.1-r3.trigger
50#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
51#6 4.754 Executing ca-certificates-20191127-r5.trigger
52#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
53#6 4.765 1 error; 36 MiB in 45 packages
54#6 ERROR: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
55------
56 > [2/2] RUN apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev:
57#6 3.958 (27/31) Installing git (2.32.0-r0)
58#6 4.559 (28/31) Installing openssh-keygen (8.6_p1-r3)
59#6 4.589 (29/31) Installing openssh-client-common (8.6_p1-r3)
60#6 4.683 (30/31) Installing openssh-client-default (8.6_p1-r3)
61#6 4.727 (31/31) Installing patch (2.7.6-r7)
62#6 4.749 Executing busybox-1.33.1-r3.trigger
63#6 4.754 ERROR: busybox-1.33.1-r3.trigger: script exited with error 1
64#6 4.754 Executing ca-certificates-20191127-r5.trigger
65#6 4.758 ERROR: ca-certificates-20191127-r5.trigger: script exited with error 1
66#6 4.765 1 error; 36 MiB in 45 packages
67------
68Dockerfile.dev:3
69--------------------
70 2 |
71 3 | >>> RUN apk update && \
72 4 | >>> apk add --no-cache composer git bash openssh-client patch && \
73 5 | >>> apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev
74 6 |
75--------------------
76error: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c apk update && apk add --no-cache composer git bash openssh-client patch && apk add --no-cache libzip-dev libpng-dev libxslt-dev curl-dev libxml2-dev icu-dev oniguruma-dev freetype-dev libjpeg-turbo-dev" did not complete successfully: exit code: 1
77make: *** [Makefile:18: feature] Error 1
78Cleaning up file based variables
7900:01
80ERROR: Job failed: exit code 2
81- mkdir -p ~/.docker/cli-plugins
82- wget -qO ~/.docker/cli-plugins/docker-buildx `wget -O - https://api.github.com/repos/docker/buildx/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4`
83- chmod a+x ~/.docker/cli-plugins/docker-buildx
84- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
85
- I was hosting the Gitlab runner on a CentOS 7 with Kernel 3.13, which is not supported by qemu. After update to Ubuntu 20.04 with Kernel version 5.4 it worked just fine.
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Composer
Tutorials and Learning Resources are not available at this moment for Composer