Last active
February 6, 2023 04:09
-
-
Save kmccarth/0ca4ad10b51b6b8034f6a660c30aafab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* VentureApp | |
* https://www.ventureapp.com/ | |
* email: info@ventureapp.com | |
*/ | |
namespace App\Helpers; | |
class vaHelper | |
{ | |
/* | |
Return just an array of certain values within a collection | |
@param1 $collection (collection) | |
@param2 $key (string as an attribute) | |
@return array | |
*/ | |
public static function pluckCollectionByKey($collection, $key) | |
{ | |
$collection = $collection->pluck($key); | |
return $collection->all(); | |
} | |
/* | |
Merge two collections together | |
@param1 $collection1 (collection) | |
@param2 $collection2 (collection) | |
@return $collection | |
*/ | |
public static function mergeTwoCollections($collection1, $collection2) | |
{ | |
$new_collection = $collection1->merge($collection2); | |
return $new_collection->all(); | |
} | |
/* | |
Strip in-line styles from a string. | |
@param $str (string) | |
@return string | |
*/ | |
public static function remove_inline_styles($str) | |
{ | |
return preg_replace('/style[^>]*/', '', $str); | |
} | |
/* | |
Quick-retreival of staff members | |
@return User collection | |
*/ | |
public static function getStaff() | |
{ | |
if (Cache::has('staff')) { | |
return Cache::get('staff'); | |
} else { | |
return Cache::remember('staff', 60, function(){ | |
return User::where('staff', 1)->get(); | |
}); | |
} | |
} | |
/* | |
Get all of the PHP comments within a file | |
@param $filename (string) | |
@return array | |
*/ | |
public static function get_php_comments($filename) | |
{ | |
$docComments = array_filter(token_get_all(file_get_contents($filename)), function($entry) | |
{ | |
return $entry[0] == T_COMMENT; | |
}); | |
$params = array(); | |
foreach($docComments as $comment){ | |
array_push($params, $comment[1]); | |
} | |
return $params; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment