/** * @param $f * @param $container * @return array|callable */ protected static function __fmap($f, $container) { /** * If $container is a simple array, just defer to array_map */ if (is_array($container)) { return Arrays::map($f, $container); } /** * If $container is a function, we defer to compose */ if ($container instanceof Closure) { return Lambda::compose($f, $container); } /** * If $container implements the Traversable interface, we can foreach over it */ if ($container instanceof Traversable) { $result = []; foreach ($container as $item) { $result[] = $f($item); } return $result; } /** * Otherwise we just need to defer to the instances' internal fmap definition */ return $container->fmap($f); }
/** * Assign Properties * * Set/Update properties on the object using a key/value array * * @example * Object::assign(['value' => 'hi!'], new stdClass); * // object(stdClass)#1 (1) { * // ["value"]=> * // string(3) "hi!" * // } * * @type array props -> Object objOriginal -> Object objUpdated * * @param $props * @param $objOriginal * @return mixed */ protected static function __assign($props, $objOriginal) { $obj = clone $objOriginal; /** @noinspection PhpParamsInspection */ return Arrays::foldl(function ($obj, $setter) { return $setter($obj); }, $obj, Arrays::mapIndexed(Lambda::flip(self::setProp()), $props)); }
protected function execute(InputInterface $input, OutputInterface $output) { // This command must be run from the project root directory. A reasonable(ly hacky) way to check this is to check for // the existence of the composer.json file. if (!file_exists(getcwd() . '/composer.json')) { $output->writeln('<error>This command must be run from the project\'s root directory.</error>'); return; } // Given a fully qualified namespace, convert \ to / and make a file path with the md extension $namespaceToPath = Lambda::compose(Strings::concat('.md'), Strings::join('/'), Strings::split('\\')); // Given a fully qualified namespace, create the containing directory $namespaceToDir = Lambda::compose(Strings::join('/'), Arrays::init(), Strings::split('\\')); // A tree that represents the organization of the modules we're generating documentation for $moduleDirectory = []; // For each module, we're going to generate a documentation file and place it in the auto-generate folder in the // root docs directory. We're going to build up the module directory as we go foreach ($input->getArgument('modules') as $module) { $moduleDoc = FunctionDocFactory::createModuleDocFromName($module); $moduleDocMarkdownDirectory = getcwd() . '/docs/auto-generate/' . $namespaceToDir($module); $moduleDocMarkdownFileLocation = getcwd() . '/docs/auto-generate/' . $namespaceToPath($module); $moduleDirectory = Lens::setL(Lens::pathLensSafe(Strings::split('\\', $module)), 'auto-generate/' . $namespaceToPath($module), $moduleDirectory); // Sort the functions in the docs alphabetically $functions = Arrays::sort(function ($fA, $fB) { return $fA->properName() <=> $fB->properName(); }, $moduleDoc->getFunctionDocs()); // For each function in this module, add the markdown content to a buffer $buffer = ''; foreach ($functions as $function) { $buffer .= $this->generateFunctionDocMarkdown($function); } // Make sure the location we're putting it exists if (!is_dir($moduleDocMarkdownDirectory)) { // 777 all day every day mkdir($moduleDocMarkdownDirectory, 0777, true); } // Then put it there file_put_contents($moduleDocMarkdownFileLocation, $buffer); } // Write the mkdocs.yml file in the project directory file_put_contents(getcwd() . '/mkdocs.yml', $this->generateMkdocsYaml($moduleDirectory)); }
protected static function __pathPropLensSafe($path) { return Lambda::compose(...Functor::fmap(function ($index) { return self::propLensSafe($index); }, $path)); }
/** * Two-Sided Chomp * * Removes the specified substring from both ends of the target string. Unlike PHP's * trim function, the substring to chomp is not a character mask -- rather it is a full * substring. This function is case sensitive. * * @example * Strings::chomp('a', 'abccba'); // 'bccb' * Strings::chomp('ab', 'abccba'); // 'abccba' * Strings::chomp('A', 'abccba'); // 'abccba' * * @type String -> String * * @param String $toChomp string to chomp * @param String $string string to be chomped * @return string */ protected static function __chomp(string $toChomp, string $string) : string { /** @noinspection PhpParamsInspection */ $chomp = Lambda::compose(self::lchomp($toChomp), self::rchomp($toChomp)); return $chomp($string); }
private function getFunctions() { $filterModule = Arrays::filter(Lambda::compose(Logic::eq($this->module->name), Object::getProp('class'))); return $filterModule($this->module->getMethods()); }