function process($directory, $category) { $files = glob($directory . '/*.xml'); foreach ($files as $file) { $contents = file_get_contents($file); if (strpos($contents, '<example>') !== false) { continue; } $examplePosition = strpos($contents, '</refentry>'); if ($examplePosition === false) { echo "{$file} couldn't find </refentry> \n"; continue; } $basename = basename($file, '.xml'); $exampleInfo = CategoryNav::findExample($category, $basename); if ($exampleInfo == null) { //echo "No example at all for $category::$basename\n"; continue; } list($exampleCategory, $exampleFunction) = $exampleInfo; $docHelper = new DocHelperDisplay($exampleCategory, $exampleFunction); $xml = $docHelper->getXML(); $start = substr($contents, 0, $examplePosition); $end = substr($contents, $examplePosition); $newContents = $start; $newContents .= $xml; $newContents .= $end; $written = @file_put_contents($file, $newContents); if ($written == false) { echo "Failed to write contents to file {$file} \n"; exit(0); } echo "Added example to {$file} \n"; //exit(0); } }
/** * @param \Auryn\Injector $injector * @param $params * @return mixed * @throws \Exception */ private function getImageResponseInternal(CategoryNav $categoryNav, \Auryn\Injector $injector, $params) { $callables = []; $cachedImageCallable = function () use($categoryNav, $params) { $category = $categoryNav->getCategory(); $example = $categoryNav->getExample(); return getCachedImageResponse($category, $example, $params); }; $directImageCallable = function () use($categoryNav, $injector, $params) { return directImageCallable($categoryNav, $injector, $params); }; $originalCallable = function (\Intahwebz\Request $request, \Auryn\Injector $injector) { \ImagickDemo\Imagick\functions::load(); $original = $request->getVariable('original', false); if ($original) { //TODO - these are not cached. //TODO - Bug waiting for pull https://github.com/rdlowrey/Auryn/pull/104 //means we can't execute directly. //return $injector->execute(['ImagickDemo\Example', 'renderOriginalImage']); $instance = $injector->make('ImagickDemo\\Example'); return $injector->execute([$instance, 'renderOriginalImage']); } return null; }; global $cacheImages; if ($cacheImages == false) { $callables[] = $originalCallable; $callables[] = $directImageCallable; } else { $callables[] = $originalCallable; //'checkGetOriginalImage'; // $callables[] = $getCachedImageResponse;// //This also reads the image when generated by a task // $callables[] = $processImageTask; //cacheImageFile //processImageTask $callables[] = $cachedImageCallable; $callables[] = $directImageCallable; //'directImageFunction'; } $result = null; foreach ($callables as $callable) { $result = $injector->execute($callable); if ($result) { return $result; } } throw new \Exception("No image callable resulted in an image response."); }
function createExample(CategoryNav $categoryNav, Injector $injector) { $exampleName = $categoryNav->getExampleName(); return $injector->make($exampleName); }