Skip to content

Instantly share code, notes, and snippets.

@daison12006013
Last active January 31, 2016 23:50
Show Gist options
  • Save daison12006013/9604880bee2b099496d5 to your computer and use it in GitHub Desktop.
Save daison12006013/9604880bee2b099496d5 to your computer and use it in GitHub Desktop.
A perfect way to convert php array into json file, works well with composer.json, and you could apply a well commented array
#!/usr/bin/env php
<?php
$props = [
'name' => 'phalconslayer/slayer',
'keywords' => [
'skeleton', 'boilerplate', 'framework', 'phalcon', 'slayer',
'bootstrap',
],
'description' => 'Bootstrapped Phalcon Framework',
'license' => 'MIT',
'require' => [
'php' => '>=5.5.9',
'phalconslayer/framework' => '1.0.*',
],
'require-dev' => [
'phpunit/phpunit' => '^4.7',
'mockery/mockery' => '^0.9.4',
'fzaninotto/faker' => '~1.4',
],
# ----------------------------------------------------------------
# Autoload Classes
# ----------------------------------------------------------------
# - the code below will be generating an array record of all
# classes listed
'autoload' => [
# - classmaps are loaded on an array, and it is much more faster
# than psr-4, however classmap's should only be applied
# for command-based generated class files
#
# - or else, you should always run "composer dumpautoload"
# to refresh the map
'classmap' => [
'app/',
'sandbox/',
],
# - psr-4 has a different way of process when composer autoloader analyze
# the location of the class, it will base on the class 'use' by reverse
# engineering the 'use' class to get the full php file path
#
# - this is why psr-4 is much more slower than classmap, however
# if you're focusing on a development part, you should apply psr-4
# instead of classmap.
#
# - and always run "composer dumpautoload --optimize" to convert
# psr-4 to classmap in the vendor/composer/autoload_classmap.php
'psr-4' => [
'Components\\' => 'components/',
]
],
'scripts' => [
'post-install-cmd' => [
'php brood optimize',
],
'post-update-cmd' => [
'php brood optimize',
],
'post-root-package-install' => [
"php -r \"copy('.env.example', '.env');\""
],
],
'config' => [
'preferred-install' => 'dist',
],
];
file_put_contents(
dirname(__DIR__) . '/composer.json',
str_replace(
'\/',
'/',
json_encode($props, JSON_PRETTY_PRINT)."\n"
)
);
print "Running (composer validate):\n";
$output = shell_exec('composer validate');
print $output;
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment