MCPcopy Create free account
hub / github.com/EqualifyEverything/equalify / get_integration_meta

Function get_integration_meta

models/integrations.php:45–81  ·  view source on GitHub ↗

* Get Integration Meta * * Modeled after WordPress's get_file_data() .. Searches for metadata in the * first 8 KB of an integration. Each piece of metadata must be on its own line. * Fields can not span multiple lines, the value will get cut at the end of the * first line. * * If the file data is not within that first 8 KB, then the author should correct * their integration file and mov

( $file )

Source from the content-addressed store, hash-verified

43 * @return string[] Array of file header values keyed by header name.
44 */
45function get_integration_meta( $file ) {
46
47 // We need to read the meta.
48 $fp = fopen( $file, 'r' );
49
50 if ( $fp ) {
51
52 // Pull only the first 8 KB of the file in.
53 $file_data = fread( $fp, 8192 );
54
55 // PHP will close file handle, but we are good citizens.
56 fclose( $fp );
57
58 } else {
59 $file_data = '';
60 }
61
62 // Make sure we catch CR-only line endings.
63 $file_data = str_replace( "\r", "\n", $file_data );
64
65 // Set headers.
66 $headers = array(
67 'name' => 'name',
68 'description' => 'description',
69 'status' => 'status'
70 );
71 foreach ( $headers as $field => $regex ) {
72 if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
73 $cleaned_header_comment = trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $match[1]) );
74 $headers[ $field ] = $cleaned_header_comment;
75 } else {
76 $headers[ $field ] = '';
77 }
78 }
79
80 return $headers;
81}
82
83/**
84 * Get Integration Fields

Callers 2

integrations.phpFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected