Skip to content

Instantly share code, notes, and snippets.

@xeno
Last active October 2, 2016 12:12
Show Gist options
  • Save xeno/994f23f352949fad644375a560e1bd94 to your computer and use it in GitHub Desktop.
Save xeno/994f23f352949fad644375a560e1bd94 to your computer and use it in GitHub Desktop.
<?php
private function loadfile( $file )
{
return require $file;
}
private function gen_param( $param, $val, $level=0 )
{
for( $t=0; $t<$level;$t++)
{
echo " ";
}
echo "* ";
echo array_key_exists( 'required', $val ) ? "\*" : "";
echo "__" . $param . "__";
if( array_key_exists( 'parameters', $val ))
{
echo "\n";
foreach( $val[ 'parameters' ] as $param2 => $val2 )
{
$this->gen_param( $param2, $val2, $level+1 );
}
}
else
{
if( array_key_exists( 'type', $val ) || array_key_exists( 'description', $val ))
{
//echo " – ";
echo array_key_exists( 'type', $val ) ? " _(" . $val[ 'type' ] . ")_&nbsp;&nbsp;" : "";
//echo array_key_exists( 'type', $val ) && (array_key_exists( 'description', $val ) && strlen( $val[ 'description' ]) > 0 ) ? ":_ " : "_";
echo array_key_exists( 'description', $val ) ? $val[ 'description' ] : "";
}
echo "\n";
}
//|" . $val[ 'type' ] . "|" . $val[ 'description' ] . "\n";
}
public function gen()
{
$dir = '../vendor/shopifyextras/shopify-php-api-wrapper/src/resources/';
$scandir = scandir( realpath( $dir ));
$resources = array();
// Load all the resources
foreach( $scandir as $file )
{
$filename = explode( '.', $file );
if( $filename[1] == 'php' )
{
$resources[ $filename[0]] = $this->loadfile( $dir . $file );
}
}
echo "<textarea style='display:block;position:absolute;top:0;bottom:0;left:0;width:100%;border:0;'>\n";
// Generate index
echo "# Shopify PHP API Wrapper - Function Reference\n";
foreach( $resources as $key => $resource )
{
echo "* [$key](#$key)\n";
}
echo "\n";
// Output functions from each resource
foreach( $resources as $key => $resource )
{
echo "<br><br>\n\n";
echo "## $key\n";
if( array_key_exists( 'operations', $resource ))
{
foreach( $resource[ 'operations' ] as $j => $operation )
{
echo "### [$j()](#$j)\n";
echo $operation[ 'summary' ] . "\n\n";
// Attributes
/*
echo "Param | Value\n";
echo "-----|-----\n";
echo "httpMethod | " . $operation[ 'httpMethod' ] . "\n";
echo "uri | " . $operation[ 'uri' ] . "\n";
echo "summary | " . $operation[ 'summary' ] . "\n";
echo "responseModel | " . $operation[ 'responseModel' ] . "\n\n";
*/
// Params
if( array_key_exists( 'parameters', $operation ))
{
foreach( $operation[ 'parameters' ] as $param => $val )
{
$this->gen_param( $param, $val );
}
echo "\n";
}
echo "<br>\n";
//print_r( $operation );
//die();
}
}
}
echo '</textarea>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment