Add $camelCase naming convention migration script; Update examples to use $camelCase naming convention

This commit is contained in:
Zach Borboa
2015-07-31 00:04:17 -07:00
parent 8d701b0648
commit 23203469c2
6 changed files with 99 additions and 6 deletions
+1 -1
View File
@@ -75,6 +75,6 @@ if (isset($_GET['code'])) {
'approval_prompt' => 'force',
));
$url = $curl->response_headers['Location'];
$url = $curl->responseHeaders['Location'];
echo '<a href="' . $url . '">Continue</a>';
}
+1 -1
View File
@@ -62,6 +62,6 @@ if (isset($_GET['code'])) {
'approval_prompt' => 'force',
));
$url = $curl->response_headers['Location'];
$url = $curl->responseHeaders['Location'];
echo '<a href="' . $url . '">Continue</a>';
}
+1 -1
View File
@@ -28,7 +28,7 @@ if (isset($_GET['code'])) {
));
if ($curl->error) {
echo $curl->response->error_type . ': ' . $curl->response->error_message . '<br />';
echo $curl->response->error_type . ': ' . $curl->response->errorMessage . '<br />';
echo '<a href="?">Try again?</a>';
exit;
}
+2 -2
View File
@@ -13,8 +13,8 @@ $multi_curl->success(function($instance) {
});
$multi_curl->error(function($instance) {
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
echo 'error code: ' . $instance->error_code . "\n";
echo 'error message: ' . $instance->error_message . "\n";
echo 'error code: ' . $instance->errorCode . "\n";
echo 'error message: ' . $instance->errorMessage . "\n";
});
$multi_curl->complete(function($instance) {
echo 'call completed' . "\n";
+1 -1
View File
@@ -11,7 +11,7 @@ $curl->post('https://httpbin.org/post', array(
));
if ($curl->error) {
echo 'Error: ' . $curl->error_message . "\n";
echo 'Error: ' . $curl->errorMessage . "\n";
} else {
echo 'Success' . "\n";
}
+93
View File
@@ -0,0 +1,93 @@
<?php
// Migrate pre-4.x.x php scripts to use current naming convention of $camelCase
// for properties / class member variables. To use, change into the directory
// containing php files that you wish to update and run this script. Example:
// $ cd /path/to/project
// $ php ../php-curl-class/scripts/v4_migration.php
$cwd = getcwd();
echo 'Checking current directory "' . $cwd . '" for possible changes.' . "\n";
$results = array(
'errors' => array(),
'files_found' => array(),
'files_to_change' => array(),
);
$migrations = array(
'error_code' => 'errorCode',
'error_message' => 'errorMessage',
'curl_error' => 'curlError',
'curl_error_code' => 'curlErrorCode',
'curl_error_message' => 'curlErrorMessage',
'http_error' => 'httpError',
'http_status_code' => 'httpStatusCode',
'http_error_message' => 'httpErrorMessage',
'base_url' => 'baseUrl',
'request_headers' => 'requestHeaders',
'response_headers' => 'responseHeaders',
'raw_response_headers' => 'rawResponseHeaders',
'raw_response' => 'rawResponse',
'before_send_function' => 'beforeSendFunction',
'download_complete_function' => 'downloadCompleteFunction',
);
$directory = new RecursiveDirectoryIterator($cwd);
$iterator = new RecursiveIteratorIterator($directory);
$regex = new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($regex as $file) {
$filepath = $file['0'];
$results['files_found'][] = $filepath;
if ($filepath === __FILE__) {
continue;
}
$data = file_get_contents($filepath);
$short_path = str_replace($cwd, '', $filepath);
if ($data === false) {
$results['errors'][] = $filepath;
echo $short_path . ' [ERROR]' . "\n";
} else {
foreach ($migrations as $old => $new) {
if (!(strpos($data, '->' . $old) === false)) {
$results['files_to_change'][] = $filepath;
echo $short_path . "\n";
break;
}
}
}
}
foreach ($results as $name => $files) {
$results[$name . '_count'] = count($files);
}
$results['errors_count'] = count($results['errors']);
$results['files_found_count'] = count($results['files_found']);
$results['files_to_change_count'] = count($results['files_to_change']);
if ($results['errors_count'] > 0) {
echo 'ERROR: Unable to read files.' . "\n";
exit(1);
} else if ($results['files_found_count'] === 0) {
echo 'Current directory "' . $cwd . '"' . "\n";
echo 'ERROR: No read files found in current directory.' . "\n";
exit(1);
} else if ($results['files_to_change_count'] === 0) {
echo 'OK: No files to change.' . "\n";
exit(0);
} else if ($results['files_to_change_count'] > 0) {
echo $results['files_to_change_count'] . ' of ' . $results['files_found_count'] . ' files to change found.' . "\n";
echo 'Continue? [y/n] ';
if (!in_array(trim(fgets(STDIN)), array('y', 'Y'))) {
die();
}
foreach ($results['files_to_change'] as $filepath) {
$data = file_get_contents($filepath);
foreach ($migrations as $old => $new) {
$data = str_replace('->' . $old, '->' . $new, $data);
}
file_put_contents($filepath, $data);
}
echo 'Done' . "\n";
exit(0);
}