Skip to content

Instantly share code, notes, and snippets.

Avatar
🍬

Mostafa Soufi mostafasoufi

🍬
View GitHub Profile
@davejamesmiller
davejamesmiller / Laravel-Container.md
Last active May 4, 2021
Laravel's Dependency Injection Container in Depth
View Laravel-Container.md

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@arubacao
arubacao / latlong.php
Last active Apr 28, 2021
Latitude Longitude Regular Expression Validation PHP
View latlong.php
<?php
/**
* Validates a given latitude $lat
*
* @param float|int|string $lat Latitude
* @return bool `true` if $lat is valid, `false` if not
*/
function validateLatitude($lat) {
return preg_match('/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/', $lat);
@theMikeD
theMikeD / acf.php
Last active Dec 19, 2018
Changes the folder where ACF loads and saves the JSON file to and from
View acf.php
<?php
add_filter('acf/settings/save_json', 'cnmd_set_acf_json_save_folder');
add_filter('acf/settings/load_json', 'cnmd_add_acf_json_load_folder');
/**
* Set a new location to save ACF field group JSON
*
* @param string $path
* @return string
*/
@james2doyle
james2doyle / simple-json-reponse.php
Last active Apr 30, 2021
A simple JSON response function for PHP. Used in various PhileCMS plugins.
View simple-json-reponse.php
<?php
function json_response($code = 200, $message = null)
{
// clear the old headers
header_remove();
// set the actual code
http_response_code($code);
// set the header to make sure cache is forced
header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
@yaronguez
yaronguez / ACF Country List
Created Feb 17, 2015
Country list formatted for Advanced Custom Fields select dropdown
View ACF Country List
afghanistan : Afghanistan
albania : Albania
algeria : Algeria
american_samoa : American Samoa
andorra : Andorra
angola : Angola
anguilla : Anguilla
antigua_and_barbuda : Antigua and Barbuda
argentina : Argentina
armenia : Armenia
@rileypaulsen
rileypaulsen / functions.php
Created Aug 19, 2014
Add Advanced Custom Fields Fields to the WP REST API
View functions.php
function wp_api_encode_acf($data,$post,$context){
$data['meta'] = array_merge($data['meta'],get_fields($post['ID']));
return $data;
}
if( function_exists('get_fields') ){
add_filter('json_prepare_post', 'wp_api_encode_acf', 10, 3);
}
@alexpchin
alexpchin / Add_Existing_Project_To_Git.md
Created Jun 1, 2014
Add Existing Project To Git Repo
View Add_Existing_Project_To_Git.md

#Adding an existing project to GitHub using the command line

Simple steps to add existing project to Github.

1. Create a new repository on GitHub.

In Terminal, change the current working directory to your local project.

##2. Initialize the local directory as a Git repository.

git init
@amacgregor
amacgregor / UserSingleton.php
Last active Mar 9, 2021
PHP Singleton pattern example
View UserSingleton.php
<?php
/** Example taken from http://www.webgeekly.com/tutorials/php/how-to-create-a-singleton-class-in-php/ **/
class User
{
// Hold an instance of the class
private static $instance;
// The singleton method
@llbbl
llbbl / awesome-php.md
Last active Apr 29, 2021 — forked from ziadoz/awesome-php.md
Awesome PHP Libraries and Resources
View awesome-php.md

Awesome PHP

A list of amazingly awesome PHP libraries, resources and shiny things.

Categories

  • Composer
  • Composer Related
  • Frameworks
  • Micro Frameworks
@reaneyk
reaneyk / gist:6604607
Created Sep 18, 2013
Example PHP Interface class
View gist:6604607
<?php
//Define a new Interface for all 'shapes' to inherit
interface Shape {
//Define the methods required for classes to implement
public function getColor();
public function setColor($color);