idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
34,100
private function registerSignals ( OutputInterface $ output ) { foreach ( $ this -> signalCallbacks as $ signal => $ callbacks ) { foreach ( $ callbacks as $ callback ) { pcntl_signal ( $ signal , function ( ) use ( $ signal , $ output , $ callback ) { if ( $ output -> isVerbose ( ) ) { $ output -> writeln ( "Received signal '$signal', calling registered callback." ) ; } return $ callback ( ) ; } ) ; } } }
Register each of the added signals for each of the callbacks .
34,101
public function getFilePath ( ) { $ path = $ this -> fileName . '.' . strtolower ( $ this -> fileExtension ) ; if ( $ this -> hasFolder ( ) ) { $ path = $ this -> folder . DIRECTORY_SEPARATOR . $ path ; } return $ path ; }
Retrieve file path .
34,102
public function add ( Command $ cmd , $ mode = RUN_REGARDLESS , $ pipe = false ) { $ cmd -> _runMode = $ mode ; $ cmd -> _pipe = ! ! $ pipe ; $ this -> commands [ ] = $ cmd ; return $ this ; }
Adds a new command to the chain
34,103
public function run ( ) { $ result = new Result ( ) ; $ resultArray = array ( ) ; $ max = count ( $ this -> commands ) ; for ( $ i = 0 ; $ i < $ max ; ++ $ i ) { $ cmd = $ this -> commands [ $ i ] ; if ( $ i === 0 ) { $ resultArray [ ] = $ result = $ cmd -> run ( ) ; continue ; } if ( ( $ cmd -> _runMode === RUN_IF_PREVIOUS_SUCCEEDS && $ result -> getExitCode ( ) !== 0 ) || ( $ cmd -> _runMode === RUN_IF_PREVIOUS_FAILS && $ result -> getExitCode ( ) === 0 ) ) { continue ; } if ( $ cmd -> _pipe ) { $ stdOut = trim ( $ result -> getStdOut ( ) ) ; $ isXArg = false ; foreach ( $ cmd as $ argIdx => $ arg ) { if ( $ arg instanceof Argument ) { if ( stripos ( $ arg -> getKey ( true ) , PIPE_PH ) !== false ) { $ key = str_replace ( PIPE_PH , $ stdOut , $ arg -> getKey ( true ) ) ; $ arg -> setKey ( $ key ) ; } $ values = $ arg -> getValues ( ) ; foreach ( $ values as $ index => $ val ) { if ( stripos ( $ val , PIPE_PH ) !== false ) { $ val = str_replace ( PIPE_PH , $ stdOut , $ val ) ; $ arg -> replaceValue ( $ index , $ val ) ; $ isXArg = true ; } } } } if ( ! $ isXArg ) { $ cmd -> setStdIn ( $ stdOut ) ; } } $ resultArray [ ] = $ result = $ cmd -> run ( ) ; } return $ resultArray ; }
Runs the command chain
34,104
public function stop ( ) { if ( ! $ this -> startTime ) { return false ; } $ this -> responseTime = $ this -> getmicrotime ( ) - $ this -> startTime ; $ this -> startTime = 0.0 ; }
Stop of measure the response time
34,105
public function findByIdentifier ( $ identifier ) { foreach ( $ this -> packages as $ package ) { if ( S :: startsWith ( $ package -> getIdentifier ( ) , $ identifier ) ) { return $ package ; } } }
Returns a package by Identifier
34,106
public function findByDirectory ( Dir $ directoryInPackage ) { foreach ( $ this -> packages as $ package ) { if ( $ directoryInPackage -> isSubdirectoryOf ( $ package -> getRootDirectory ( ) ) || $ directoryInPackage -> equals ( $ package -> getRootDirectory ( ) ) ) { return $ package ; } } }
Returns a package by some of its sub directories
34,107
public function addComposerPackageFromDirectory ( Dir $ dir ) { $ package = $ this -> getComposerPackageReader ( ) -> fromDirectory ( $ dir ) ; $ this -> addPackage ( $ package ) ; return $ package ; }
Adds a composer package from a directory
34,108
private function initDOMXPath ( ) { $ this -> xpath = new DOMXPath ( $ this ) ; $ simpleXML = new \ SimpleXMLElement ( $ this -> saveXML ( ) ) ; $ namespaces = $ simpleXML -> getNamespaces ( true ) ; foreach ( $ namespaces as $ name => $ uri ) { $ name = $ name ? : self :: ROOT_NAMESPACE_NAME ; $ this -> namespaces [ $ name ] = $ uri ; $ this -> xpath -> registerNamespace ( $ name , $ uri ) ; } return $ this ; }
Initialisation XPath .
34,109
public function relatedCollection ( $ resourceModel , RelatedRepository $ repository ) { if ( $ repository instanceof ConditionAwareRepository ) { $ this -> applyFilters ( $ this -> filters , $ this -> filterFactory , $ repository ) ; } if ( $ repository instanceof OneToOneRelationRepository ) { return $ repository -> getOne ( $ resourceModel ) ; } if ( $ repository instanceof OneToManyRelationRepository ) { return $ repository -> getMany ( $ resourceModel ) ; } throw new \ InvalidArgumentException ( 'Repository ' . get_class ( $ repository ) . ' has no relation repository interface defined.' ) ; }
relationship index request
34,110
public function getConditionByType ( string $ repositoryType ) : Collection { return $ this -> conditions -> filter ( function ( RepositoryCondition $ condition ) use ( $ repositoryType ) { return $ condition instanceof $ repositoryType ; } ) ; }
returns condition by type
34,111
public function apply ( TakesConditions $ builder ) { $ peeking = $ this -> peek ; $ this -> peek = false ; foreach ( $ this -> conditions as $ condition ) { $ condition -> apply ( $ builder ) ; } if ( $ peeking ) { return ; } $ this -> conditions = new Collection ( ) ; }
takes a condition
34,112
public function isInPerimeter ( $ item , PerimeterInterface $ perimeter ) { if ( isset ( $ this -> strategies [ $ perimeter -> getType ( ) ] ) ) { return $ this -> strategies [ $ perimeter -> getType ( ) ] -> isInPerimeter ( $ item , $ perimeter ) ; } return false ; }
Check if a path is contained in the perimeter
34,113
public function setPath ( $ path = "" ) { if ( $ path != "" ) { $ this -> _path = str_replace ( "\\" , DS , $ path ) ; $ this -> _path = ( substr ( $ this -> _path , - 1 ) == DS ) ? substr ( $ this -> _path , 0 , - 1 ) : $ this -> _path ; } }
Set the explorer path
34,114
public static function lengthSort ( $ val_1 , $ val_2 ) { $ retVal = 0 ; $ firstVal = strlen ( $ val_1 ) ; $ secondVal = strlen ( $ val_2 ) ; if ( $ firstVal > $ secondVal ) { $ retVal = 1 ; } elseif ( $ firstVal < $ secondVal ) { $ retVal = - 1 ; } return $ retVal ; }
Sort an array based on the strings length
34,115
public function uploadPhoto ( ) { $ result = [ ] ; if ( $ this -> validate ( ) ) { $ fileOrgname = Helper :: validateFilename ( $ this -> file -> name , 40 ) ; $ filename = $ fileOrgname ; $ filePath = Media :: getCurrentDirectory ( ) . DIRECTORY_SEPARATOR . $ filename ; $ result [ 'originName' ] = $ this -> file -> name ; if ( $ this -> file -> saveAs ( $ filePath ) ) { $ result [ 'originPath' ] = $ filePath ; if ( $ this -> options -> resize ) { $ tsize = ( new Size ( getimagesize ( $ filePath ) ) ) -> resize ( $ this -> options -> resizeTo ) ; $ size = new \ Imagine \ Image \ Box ( $ tsize -> width , $ tsize -> height ) ; $ imagine = new \ Imagine \ Gd \ Imagine ( ) ; $ resizedName = 'primary_' . $ filename ; $ resizedPath = Media :: getCurrentDirectory ( ) . DIRECTORY_SEPARATOR . $ resizedName ; $ imagine -> open ( $ filePath ) -> resize ( $ size ) -> save ( $ resizedPath ) ; $ filename = $ resizedName ; $ filePath = $ resizedPath ; } $ result [ 'success' ] = true ; $ result [ 'fileName' ] = $ filename ; $ result [ 'filePath' ] = $ filePath ; $ result [ 'size' ] = filesize ( $ filePath ) ; if ( $ this -> options -> generateThumbnail ) { $ thumbName = 'thumb_' . $ fileOrgname ; $ thumbPath = Media :: getCurrentDirectory ( ) . DIRECTORY_SEPARATOR . $ thumbName ; $ tsize = ( new Size ( getimagesize ( $ filePath ) ) ) -> resize ( $ this -> options -> thumbnailSize ) ; $ size = new \ Imagine \ Image \ Box ( $ tsize -> width , $ tsize -> height ) ; $ imagine = new \ Imagine \ Gd \ Imagine ( ) ; try { $ imagine -> open ( $ filePath ) -> thumbnail ( $ size ) -> save ( $ thumbPath ) ; $ result [ 'thumbnailPath' ] = $ thumbPath ; $ result [ 'thumbnailName' ] = $ thumbName ; } catch ( \ Exception $ e ) { \ Yii :: $ app -> log -> logger -> log ( $ e ) ; } } } } $ result [ 'error' ] = new ModelErrors ( $ this -> getErrors ( ) ) ; return new UploadResult ( $ result ) ; }
Upload and process the photo file
34,116
public function registerManager ( ) { $ this -> app -> singleton ( 'nodes.assets' , function ( $ app ) { $ uploadProvider = call_user_func ( config ( 'nodes.assets.general.upload.provider' ) , $ app ) ; $ urlProvider = call_user_func ( config ( 'nodes.assets.general.url.provider' ) , $ app ) ; return new Manager ( $ uploadProvider , $ urlProvider ) ; } ) ; }
Register assets manager .
34,117
public static function is_mobile ( ) { if ( ! isset ( $ _SERVER [ 'HTTP_ACCEPT' ] ) ) { return false ; } $ accept = $ _SERVER [ 'HTTP_ACCEPT' ] ; if ( isset ( $ _SERVER [ 'HTTP_X_WAP_PROFILE' ] ) || isset ( $ _SERVER [ 'HTTP_PROFILE' ] ) ) { return true ; } elseif ( strpos ( $ accept , 'text/vnd.wap.wml' ) > 0 || strpos ( $ accept , 'application/vnd.wap.xhtml+xml' ) > 0 ) { return true ; } else { foreach ( array_keys ( self :: $ devices ) as $ device ) { if ( self :: is_device ( $ device ) ) return true ; } } return false ; }
Check if we are in the mobile mode
34,118
public static function get_device ( ) { foreach ( array_keys ( self :: $ devices ) as $ device ) { if ( self :: is_device ( $ device ) ) return $ device ; } }
Return normalised name of a device
34,119
protected static function is_device ( $ device ) { $ ua = $ _SERVER [ 'HTTP_USER_AGENT' ] ; return ( bool ) preg_match ( "/" . self :: $ devices [ $ device ] . "/i" , $ ua ) ; }
Check if navigateur is a current devise
34,120
public function dir ( $ identifier ) { if ( $ identifier === 'root' ) { return $ this -> getRootDirectory ( ) ; } elseif ( $ this -> directoryLocations -> has ( $ identifier ) ) { return $ this -> directoryLocations -> get ( $ identifier ) ; } else { return $ this -> package -> getDirectory ( $ identifier ) ; } }
Returns a semantic directory for the project
34,121
public function getPath ( $ path , $ flags = 0x000000 ) { if ( ( $ flags & self :: RELATIVE ) === self :: RELATIVE ) { $ path = $ this -> dir . ltrim ( $ path , '\\/' ) ; } if ( ( $ flags & self :: VALIDATE ) === self :: VALIDATE ) { if ( ( $ rPath = realpath ( $ path ) ) !== FALSE ) { $ path = $ rPath ; } else { throw new Exception ( 'Pfad: ' . $ path . ' konnte nicht gefunden werden' , self :: VALIDATE ) ; } } return $ this -> ts ( $ path ) ; }
resolves a path to a full path
34,122
public function tryPath ( $ path , $ flags = 0x000000 ) { $ flags |= self :: VALIDATE ; try { return $ this -> getPath ( $ path , $ flags ) ; } catch ( Exception $ e ) { if ( $ e -> getCode ( ) === self :: VALIDATE ) { return FALSE ; } else { throw $ e ; } } }
tries to resolve a path
34,123
public function scan ( ) { if ( $ this -> scanned == true ) { return $ this ; } if ( is_dir ( $ path = $ this -> getPath ( ) ) ) { $ found = $ this -> finder -> in ( $ path ) -> files ( ) -> name ( self :: FILENAME ) -> depth ( '== 1' ) -> followLinks ( ) ; foreach ( $ found as $ file ) { $ this -> themes [ ] = new Theme ( $ this -> getInfo ( $ file ) ) ; } } $ this -> scanned = true ; return $ this ; }
Find the specified theme by searching a theme . json file as identifier .
34,124
protected function getInfo ( $ file ) { $ attributes = Json :: make ( $ path = $ file -> getRealPath ( ) ) -> toArray ( ) ; $ attributes [ 'path' ] = dirname ( $ path ) ; return $ attributes ; }
Get theme info from json file .
34,125
public function getServerDate ( $ format = null ) { $ node = $ this -> getFirst ( '//epp:epp/epp:greeting/epp:svDate' ) ; if ( $ format === null ) { return $ node -> nodeValue ; } return date_create_from_format ( $ format , $ node -> nodeValue ) ; }
Server s current date and time .
34,126
public static function create ( $ name , $ type = NULL , $ defaultValue = self :: UNDEFINED , $ reference = FALSE ) { if ( isset ( $ type ) ) { if ( $ type instanceof GClass ) { $ type = new ObjectType ( new GClass ( $ type -> getFQN ( ) ) ) ; } elseif ( ! ( $ type instanceof Type ) ) { $ type = Type :: create ( $ type ) ; } } return new static ( $ name , $ type , $ defaultValue , $ reference ) ; }
Creates a new Parameter
34,127
protected function overrideViewPath ( ) { $ this -> app -> bind ( 'view.finder' , function ( $ app ) { $ defaultThemePath = $ app [ 'config' ] [ 'themes.path' ] . '/' . $ app [ 'config' ] [ 'themes.default' ] . '/views' ; if ( is_dir ( $ defaultThemePath ) ) { $ paths = [ $ defaultThemePath ] ; } else { $ paths = $ app [ 'config' ] [ 'view.paths' ] ; } return new FileViewFinder ( $ app [ 'files' ] , $ paths ) ; } ) ; }
Override view path .
34,128
public function isAvailable ( $ contactId ) { $ contactcdNode = $ this -> getContactcd ( $ contactId ) ; $ node = $ this -> getFirst ( 'contact:id' , $ contactcdNode ) ; return in_array ( $ node -> getAttribute ( 'avail' ) , [ '1' , 'true' ] ) ; }
Contact is available for creating .
34,129
public function getReason ( $ contactId ) { $ contactcdNode = $ this -> getContactcd ( $ contactId ) ; $ node = $ this -> getFirst ( 'contact:reason' , $ contactcdNode ) ; return $ node === null ? null : $ node -> nodeValue ; }
The reason why a contact is not available for creation .
34,130
public function selectRenderer ( ViewEvent $ e ) { $ model = $ e -> getModel ( ) ; if ( $ model instanceof ImageModel ) { if ( ! $ model -> getImage ( ) instanceof ImageInterface ) { if ( ! $ model -> getImagePath ( ) ) { throw new Exception \ RuntimeException ( 'You must provide Imagine\Image\ImageInterface or path of image' ) ; } $ model -> setImage ( $ this -> imagine -> open ( $ model -> getImagePath ( ) ) ) ; } return new ImageRenderer ( ) ; } }
Sets ImageRenderer as Renderer when ImageModel is used
34,131
public function injectResponse ( ViewEvent $ e ) { $ model = $ e -> getModel ( ) ; if ( $ model instanceof ImageModel ) { $ result = $ e -> getResult ( ) ; $ response = $ e -> getResponse ( ) ; $ response -> setContent ( $ result ) ; $ response -> getHeaders ( ) -> addHeaderLine ( 'Content-type' , $ this -> getMimeType ( $ model -> getFormat ( ) ) ) ; } }
Sets the response based on image returned by the renderer
34,132
public function setCACertificates ( $ path , $ type ) { if ( ! in_array ( $ type , array ( 'capath' , 'cainfo' ) ) ) { throw new \ OtherCode \ Rest \ Exceptions \ RestException ( 'Invalid param "type" in for ' . __METHOD__ . 'method.' ) ; } $ this -> ssl_verifypeer = true ; $ this -> ssl_verifyhost = 2 ; $ this -> $ type = $ path ; return $ this ; }
Set a CA Certificate to validate peers
34,133
public function toArray ( ) { $ array = array ( ) ; $ allowed = get_class_vars ( get_class ( $ this ) ) ; foreach ( get_object_vars ( $ this ) as $ key => $ item ) { if ( array_key_exists ( $ key , $ allowed ) && isset ( $ item ) ) { $ array [ constant ( strtoupper ( "CURLOPT_" . $ key ) ) ] = ( method_exists ( $ item , 'build' ) ? $ item -> build ( ) : $ item ) ; } } return $ array ; }
Transform the object to array .
34,134
public function getUpdateDate ( $ format = null ) { $ node = $ this -> getFirst ( '//epp:epp/epp:response/epp:resData/host:infData/host:upDate' ) ; if ( $ node === null ) { return null ; } if ( $ format === null ) { return $ node -> nodeValue ; } return date_create_from_format ( $ format , $ node -> nodeValue ) ; }
Date and time of host object updating .
34,135
protected function compileComments ( $ value ) { $ pattern = sprintf ( '/%s#((.|\s)*?)%s/' , $ this -> contentTags [ 0 ] , $ this -> contentTags [ 1 ] ) ; $ value = preg_replace ( $ pattern , '<?php /* $1 */ ?>' , $ value ) ; $ pattern = sprintf ( '/%s--((.|\s)*?)--%s/' , '{{' , '}}' ) ; $ value = preg_replace ( $ pattern , '<?php /* $1 */ ?>' , $ value ) ; return $ value ; }
Compile Tpl comments into valid PHP .
34,136
protected function checkPasswords ( ) { if ( $ this -> getOriginal ( 'password' ) != $ this -> password ) { if ( $ this -> password === $ this -> password_confirmation ) { $ this -> password = bcrypt ( $ this -> password ) ; unset ( $ this -> password_confirmation ) ; } else { return false ; } } return true ; }
Check if the passwords match
34,137
protected function registerServiceProviders ( ) { $ list = new ProviderList ( Core :: getFacadeRoot ( ) ) ; foreach ( $ this -> providers as $ provider ) { $ list -> registerProvider ( $ provider ) ; if ( method_exists ( $ provider , 'boot' ) ) { Core :: make ( $ provider ) -> boot ( $ this ) ; } } }
Register the packages defined service providers .
34,138
protected function bootComposer ( ) { $ filesystem = new Filesystem ( ) ; $ path = __DIR__ . '/vendor/autoload.php' ; if ( $ filesystem -> exists ( $ path ) ) { $ filesystem -> getRequire ( $ path ) ; } }
Boot the packages composer autoloader if it s present .
34,139
public function path ( $ file = null ) { $ base_path = Composer :: getRootPath ( ) ; $ pieces = explode ( '/' , $ file ) ; array_splice ( $ pieces , 2 , 0 , 'public' ) ; $ vendor_path = implode ( '/' , $ pieces ) ; if ( is_file ( $ base_path . '/workbench/' . $ vendor_path ) ) { return $ base_path . '/workbench/' . $ vendor_path ; } elseif ( is_file ( $ base_path . '/vendor/' . $ vendor_path ) ) { return $ base_path . '/vendor/' . $ vendor_path ; } else { foreach ( $ this -> _paths as $ path ) { $ currentPath = $ base_path . '/' . $ path . '/' . $ file ; if ( is_file ( $ currentPath ) ) { return $ currentPath ; } } } return false ; }
Check file from registered path
34,140
public static function loadEnvironment ( $ env = null ) { $ env = $ env ? $ env : static :: $ env ; foreach ( ( array ) static :: $ loadedPaths as $ path ) { if ( is_dir ( $ path . DS . $ env ) ) { self :: load ( $ path . DS . $ env ) ; } } }
Load an environment defined or not
34,141
public static function load ( $ mPath , $ sNamespace = null ) { if ( is_array ( $ mPath ) && ! empty ( $ mPath ) ) { $ aFiles = $ mPath ; } elseif ( strpos ( $ mPath , '.' ) > 0 && ! is_null ( Arr :: get ( static :: $ aSettings , $ mPath ) ) ) { $ tmp = Arr :: get ( static :: $ aSettings , $ mPath ) ; $ aFiles = glob ( substr ( $ tmp , - 1 ) === '/' ? $ tmp . '*.php' : $ tmp ) ; } else { $ aFiles = glob ( substr ( $ mPath , - 1 ) === '/' ? $ mPath . '*.php' : $ mPath ) ; } foreach ( $ aFiles as $ sFilePath ) { $ pathinfo = pathinfo ( $ sFilePath ) ; $ key = ! is_null ( $ sNamespace ) ? $ sNamespace . '.' . $ pathinfo [ 'filename' ] : $ pathinfo [ 'filename' ] ; if ( ! is_int ( array_search ( $ sFilePath , $ aFiles ) ) ) { $ key = array_search ( $ sFilePath , $ aFiles ) ; } if ( ! is_null ( Arr :: get ( static :: $ aSettings , $ key ) ) ) { static :: set ( $ key , Arr :: merge ( static :: get ( $ key ) , include $ sFilePath ) ) ; } elseif ( is_file ( $ sFilePath ) ) { static :: set ( $ key , include $ sFilePath ) ; } } return static :: getInstance ( ) ; }
Load single or multiple file configuration .
34,142
public static function needs ( $ sNeedle , $ sCallback = null , $ aArgs = null ) { if ( ! is_null ( static :: get ( $ sNeedle ) ) ) { return true ; } elseif ( ! is_null ( $ sCallback ) ) { if ( is_array ( $ aArgs ) ) { return call_user_func_array ( $ sCallback , $ aArgs ) ; } return call_user_func ( $ sCallback ) ; } return false ; }
Request a particular config .
34,143
public function append ( ) { foreach ( func_get_args ( ) as $ value ) { if ( $ value instanceof ResultInterface || $ value instanceof ApiException || is_callable ( $ value ) ) { $ this -> queue [ ] = $ value ; } else { throw new \ InvalidArgumentException ( 'Expected an Api\ResultInterface or Api\Exception\ApiException.' ) ; } } }
Adds one or more variadic ResultInterface or ApiException objects to the queue .
34,144
protected function prepareStatements ( ) { if ( ! empty ( $ this -> statements ) ) { return ; } $ this -> statements [ 'load' ] = $ this -> db -> prepare ( 'SELECT * FROM `' . $ this -> options [ 'table' ] . '` WHERE `userId` = :userId ' . 'AND `scope` = :scope AND `name` = :name AND `args` = :args' ) ; $ this -> statements [ 'save' ] = $ this -> db -> prepare ( 'INSERT INTO `' . $ this -> options [ 'table' ] . '` (`userId`, `scope`, `name`, `args`, `cachedUntil`, `xml`) VALUES ' . '(:userId, :scope, :name, :args, :cachedUntil, :xml)' ) ; $ this -> statements [ 'delete' ] = $ this -> db -> prepare ( 'DELETE FROM`' . $ this -> options [ 'table' ] . '` WHERE `userId` = :userId ' . 'AND `scope` = :scope AND `name` = :name AND `args` = :args' ) ; }
Prepares the PDO statements
34,145
protected function serializeArguments ( array $ args ) { ksort ( $ args ) ; $ result = '' ; $ invalidKeys = array ( 'userid' , 'apikey' , 'keyid' , 'vcode' ) ; foreach ( $ args as $ key => $ value ) { $ key = trim ( $ key ) ; $ value = trim ( $ value ) ; if ( empty ( $ value ) || in_array ( $ key , $ invalidKeys ) ) { continue ; } $ result .= ';' . $ key . '=' . $ value ; } return $ result ; }
Serializes the arguments into a string
34,146
public function border ( $ color = '#000000' , $ thickness = 1 ) { $ rgb = $ this -> hex2rgb ( $ color ) ; $ color = imagecolorallocate ( $ this -> image , $ rgb [ 'r' ] , $ rgb [ 'g' ] , $ rgb [ 'b' ] ) ; $ x1 = 0 ; $ y1 = 0 ; $ x2 = ImageSX ( $ this -> image ) - 1 ; $ y2 = ImageSY ( $ this -> image ) - 1 ; for ( $ i = 0 ; $ i < $ thickness ; $ i ++ ) { ImageRectangle ( $ this -> image , $ x1 ++ , $ y1 ++ , $ x2 -- , $ y2 -- , $ color ) ; } return $ this ; }
Add a border to the picture
34,147
public function flip ( $ direction ) { $ new = imagecreatetruecolor ( $ this -> width , $ this -> height ) ; imagealphablending ( $ new , false ) ; imagesavealpha ( $ new , true ) ; switch ( strtolower ( $ direction ) ) { case 'y' : for ( $ y = 0 ; $ y < $ this -> height ; $ y ++ ) { imagecopy ( $ new , $ this -> image , 0 , $ y , 0 , $ this -> height - $ y - 1 , $ this -> width , 1 ) ; } break ; default : for ( $ x = 0 ; $ x < $ this -> width ; $ x ++ ) { imagecopy ( $ new , $ this -> image , $ x , 0 , $ this -> width - $ x - 1 , 0 , 1 , $ this -> height ) ; } break ; } $ this -> image = $ new ; return $ this ; }
Flip an image horizontally or vertically
34,148
public function output ( $ quality = null ) { header ( 'Content-type: image/' . $ this -> original_info [ 'format' ] ) ; $ this -> save ( - 1 , $ quality ) ; die ( ) ; }
output the Data as image
34,149
public function outputBase64 ( $ quality = null ) { ob_start ( ) ; $ this -> save ( - 1 , $ quality ) ; $ image_data = ob_get_contents ( ) ; ob_end_clean ( ) ; return 'data:' . $ this -> original_info [ 'mime' ] . ';base64,' . base64_encode ( $ image_data ) ; }
Output the data in Base64 on the supafly
34,150
private function imagecopymerge_alpha ( $ dst_im , $ src_im , $ dst_x , $ dst_y , $ src_x , $ src_y , $ src_w , $ src_h , $ pct ) { $ pct /= 100 ; $ w = imagesx ( $ src_im ) ; $ h = imagesy ( $ src_im ) ; imagealphablending ( $ src_im , false ) ; $ minalpha = 127 ; for ( $ x = 0 ; $ x < $ w ; $ x ++ ) { for ( $ y = 0 ; $ y < $ h ; $ y ++ ) { $ alpha = ( imagecolorat ( $ src_im , $ x , $ y ) >> 24 ) & 0xFF ; if ( $ alpha < $ minalpha ) { $ minalpha = $ alpha ; } } } for ( $ x = 0 ; $ x < $ w ; $ x ++ ) { for ( $ y = 0 ; $ y < $ h ; $ y ++ ) { $ colorxy = imagecolorat ( $ src_im , $ x , $ y ) ; $ alpha = ( $ colorxy >> 24 ) & 0xFF ; if ( $ minalpha !== 127 ) { $ alpha = 127 + 127 * $ pct * ( $ alpha - 127 ) / ( 127 - $ minalpha ) ; } else { $ alpha += 127 * $ pct ; } $ alphacolorxy = imagecolorallocatealpha ( $ src_im , ( $ colorxy >> 16 ) & 0xFF , ( $ colorxy >> 8 ) & 0xFF , $ colorxy & 0xFF , $ alpha ) ; if ( ! imagesetpixel ( $ src_im , $ x , $ y , $ alphacolorxy ) ) { return false ; } } } imagecopy ( $ dst_im , $ src_im , $ dst_x , $ dst_y , $ src_x , $ src_y , $ src_w , $ src_h ) ; }
Copymerge with preserves alpha - transparency in 24 - bit PNGs
34,151
public function parse ( CurlResponse $ curlResponse ) { $ responseBody = $ curlResponse -> getBody ( ) ; $ contentType = $ curlResponse -> info ( ) -> getContentType ( ) ; $ responseType = $ this -> getResponseType ( $ contentType ) ; $ responseCharset = $ this -> getResponseCharset ( $ contentType ) ; $ httpCode = $ curlResponse -> info ( ) -> getHttpCode ( ) ; $ httpMessage = $ this -> responseCodes -> getMessage ( $ httpCode ) ; return new Response ( $ responseBody , $ responseType , $ responseCharset , $ httpCode , $ httpMessage ) ; }
Convert the Curl response into a Courier response
34,152
private function getResponseType ( $ contentType ) { $ length = strpos ( $ contentType , ';' ) ? : null ; $ type = $ length ? substr ( $ contentType , 0 , $ length ) : $ contentType ; return strtolower ( trim ( $ type ) ) ; }
Get the response type
34,153
private function getResponseCharset ( $ contentType ) { $ start = strpos ( $ contentType , '=' ) ; $ type = '' ; if ( $ start !== false ) { $ type = strtoupper ( trim ( substr ( $ contentType , $ start + 1 ) ) ) ; } return $ type ; }
Get the response charset
34,154
public static function findByAttribute ( $ attribute , $ value , $ columns = [ '*' ] ) { $ model = new static ; return $ model -> where ( $ attribute , '=' , $ value ) -> first ( $ columns ) ; }
Load the first entity by it s attribute
34,155
protected function isNativeAttribute ( $ key ) { if ( $ this -> timestamps && in_array ( $ key , [ 'updated_at' , 'created_at' ] ) ) { return true ; } elseif ( $ key == $ this -> primaryKey ) { return true ; } return false ; }
Determine if key is a native attribute
34,156
protected function prepareConfig ( ) { $ config = config ( "entity" , [ ] ) ; $ entity = $ this -> entity ; if ( ! isset ( $ config [ $ entity ] ) ) { throw new \ Exception ( "No configuration found for entity {$entity}." ) ; } $ this -> config = $ config [ $ entity ] + [ 'attributes' => [ ] , 'relationships' => [ ] , 'scope' => Scope :: DISABLED , ] ; foreach ( $ this -> config [ 'attributes' ] as $ attr => $ values ) { $ this -> config [ 'attributes' ] [ $ attr ] = $ this -> applyAttributeDefaults ( $ values ) ; } foreach ( $ this -> config [ 'relationships' ] as $ rel => $ values ) { $ this -> config [ 'relationships' ] [ $ rel ] = $ this -> applyRelationshipDefaults ( $ values ) ; } $ this -> fillable ( array_keys ( $ this -> config [ 'attributes' ] ) ) ; }
Reload the configuration and set fillable attributes .
34,157
protected function prepareAttributes ( $ attributes ) { foreach ( $ this -> getAttributeConfig ( ) as $ attr => $ config ) { if ( ! isset ( $ this -> attributes [ $ attr ] ) && ! isset ( $ attributes [ $ attr ] ) ) { $ attributes [ $ attr ] = $ config [ 'default' ] ; } } foreach ( $ attributes as $ key => $ value ) { if ( isset ( $ this -> config [ 'attributes' ] [ $ key ] ) ) { $ attributes [ $ key ] = $ this -> $ key ( ) -> before_save ( $ value ) ; } elseif ( isset ( $ this -> config [ 'relationships' ] [ $ key ] ) ) { unset ( $ attributes [ $ key ] ) ; $ relationship = $ this -> config [ 'relationships' ] [ $ key ] ; $ this -> translateShorthand ( $ value ) ; switch ( $ relationship [ 'type' ] ) { case Relationship :: HAS_PIVOT : if ( $ value instanceof Collection ) $ value = $ value -> all ( ) ; if ( $ value instanceof EntityContract ) $ value = [ $ value ] ; $ this -> $ key ( ) -> saveMany ( $ value ) ; break ; case Relationship :: HAS_MANY : $ this -> $ key ( ) -> saveMany ( ( array ) $ value ) ; break ; case Relationship :: BELONGS_TO : $ this -> $ key ( ) -> associate ( $ value ) ; break ; case Relationship :: HAS_ONE : $ this -> $ key ( ) -> save ( $ value ) ; break ; default : throw new \ Exception ( sprintf ( "Unknown relationship type \"%s\" on entity \"%s\"" , $ relationship [ 'type' ] , $ relationship [ 'entity' ] ) ) ; break ; } } } return $ attributes ; }
Save various model relationships ; used when creating a new entity todo move to relationship model
34,158
private function recursiveCallChild ( \ DOMNodeList $ nodeList , callable $ fct ) { foreach ( $ nodeList as $ domNode ) { $ fct ( new GlHtmlNode ( $ domNode ) ) ; if ( $ domNode -> hasChildNodes ( ) ) { $ this -> recursiveCallChild ( $ domNode -> childNodes , $ fct ) ; } } }
extract h tag from html
34,159
public static function alias ( $ aliasName , $ callback ) { $ err = false ; if ( function_exists ( $ aliasName ) ) { $ err = 'This function already' . $ aliasName . ' exists' ; } if ( ! is_callable ( $ callback , false , $ realfunc ) ) { $ err = $ callback . ' is not callable' ; } if ( $ err === false ) { try { $ bodyFunc = 'function ' . $ aliasName . '() { $args = func_get_args(); return call_user_func_array("' . $ realfunc . '", $args); }' ; eval ( $ bodyFunc ) ; return array ( 'result' => true , 'msg' => "function $aliasName created from $callback" ) ; } catch ( \ Exception $ e ) { $ trace = debug_backtrace ( ) ; $ msg = sprintf ( '%s(): %s in %s on line %d' , $ trace [ 0 ] [ 'function' ] , $ err , $ trace [ 0 ] [ 'file' ] , $ trace [ 0 ] [ 'line' ] ) ; trigger_error ( $ msg , E_USER_WARNING ) ; return array ( 'result' => false , 'msg' => $ err ) ; } } else { return array ( 'result' => false , 'msg' => $ err ) ; } }
Create an Alias of a function check if it s exist
34,160
public static function genAlphaColumns ( $ end_column , $ first_letters = '' ) { $ columns = array ( ) ; $ length = strlen ( $ end_column ) ; $ letters = range ( 'A' , 'Z' ) ; foreach ( $ letters as $ letter ) { $ column = $ first_letters . $ letter ; $ columns [ ] = $ column ; if ( $ column == $ end_column ) return $ columns ; } foreach ( $ columns as $ column ) { if ( ! in_array ( $ end_column , $ columns ) && strlen ( $ column ) < $ length ) { $ new_columns = self :: genAlphaColumns ( $ end_column , $ column ) ; $ columns = array_merge ( $ columns , $ new_columns ) ; } } return $ columns ; }
This will generate alphabetical columns
34,161
public static function getVideoEmbed ( $ url , $ width = 560 , $ height = 315 ) { switch ( true ) { case preg_match ( '/youtu/i' , $ url ) : $ id = self :: getVideoId ( $ url ) ; if ( ! $ id ) { return '<iframe width="' . $ width . '" height="' . $ height . '" src="//www.youtube.com/embed/' . $ id . '?rel=0" frameborder="0" allowfullscreen></iframe>' ; } return false ; case preg_match ( '/vimeo/i' , $ url ) : $ id = self :: getVideoId ( $ url ) ; if ( ! $ id ) { return '<iframe src="//player.vimeo.com/video/' . $ id . '?portrait=0" width="' . $ width . '" height="' . $ height . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>' ; } return false ; case preg_match ( '/dailymotion/i' , $ url ) : $ id = self :: getVideoId ( $ url ) ; if ( ! $ id ) { return '<iframe frameborder="0" width="' . $ width . '" height="' . $ height . '" src="//www.dailymotion.com/embed/video/' . $ id . '"></iframe>' ; } return false ; } }
Get Video embed from Youtube Vimeo or Dailymotion
34,162
public static function isJson ( $ string ) { if ( ! is_string ( $ string ) ) return false ; if ( empty ( $ string ) ) return false ; json_decode ( $ string ) ; return ( json_last_error ( ) == JSON_ERROR_NONE ) ; }
check if string is json
34,163
public static function isHTTPS ( $ server = array ( ) ) { $ response = false ; if ( empty ( $ server ) && isset ( $ _SERVER ) ) { $ server = $ _SERVER ; if ( ! isset ( $ server [ 'SERVER_PORT' ] ) ) { $ server [ 'SERVER_PORT' ] = 80 ; } } else { $ server [ 'HTTPS' ] = getenv ( 'HTTPS' ) ; $ server [ 'SERVER_PORT' ] = getenv ( 'SERVER_PORT' ) ; } if ( isset ( $ server [ 'HTTPS' ] ) && $ server [ 'HTTPS' ] !== 'off' || $ server [ 'SERVER_PORT' ] == 443 ) { $ response = true ; } return $ response ; }
Function to check if the Server is on HTTPS or not
34,164
public static function randArray ( array $ array , $ param = array ( ) ) { if ( ! is_array ( $ param ) ) { $ param = json_decode ( $ param , true ) ; } $ defParam = array ( ) ; $ param = Arr :: merge ( $ defParam , $ param ) ; if ( ! empty ( $ param [ 'take' ] ) ) { $ response = array ( ) ; for ( $ i = 1 ; $ i <= $ param [ 'take' ] ; $ i ++ ) { $ response [ ] = $ array [ array_rand ( $ array , 1 ) ] ; } return $ response ; } else { return $ array [ array_rand ( $ array , 1 ) ] ; } }
Random an array
34,165
public static function resizeThumbnailImage ( $ thumb_image_name , $ image , $ width , $ height , $ start_width , $ start_height , $ scale ) { $ newImageWidth = ceil ( $ width * $ scale ) ; $ newImageHeight = ceil ( $ height * $ scale ) ; $ newImage = imagecreatetruecolor ( $ newImageWidth , $ newImageHeight ) ; $ source = imagecreatefromjpeg ( $ image ) ; imagecopyresampled ( $ newImage , $ source , 0 , 0 , $ start_width , $ start_height , $ newImageWidth , $ newImageHeight , $ width , $ height ) ; imagejpeg ( $ newImage , $ thumb_image_name , 90 ) ; chmod ( $ thumb_image_name , 0777 ) ; return $ thumb_image_name ; }
Quick resize image function
34,166
protected function addYoutubeForm ( FormBuilderInterface $ builder ) { $ builder -> add ( 'youtubeVideoId' , 'oo_video' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.video_id' , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeWidth' , 'text' , array ( 'empty_data' => '480' , 'label' => 'open_orchestra_backoffice.block.video.youtube.width' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeHeight' , 'text' , array ( 'empty_data' => '269' , 'label' => 'open_orchestra_backoffice.block.video.youtube.height' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeAutoplay' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.autoplay' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeFs' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.fs' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeHl' , 'orchestra_language' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.hl' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , ) ) -> add ( 'youtubeShowinfo' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.showinfo' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeRel' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.rel.title' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' , 'help_text' => 'open_orchestra_backoffice.block.video.youtube.rel.helper' ) , ) ) -> add ( 'youtubeDisablekb' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.disablekb' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeLoop' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.loop' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeControls' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.controls' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeTheme' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.theme' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) -> add ( 'youtubeColor' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.youtube.color' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'youtube' ) ) ) ; }
Add to the video form the youtube part
34,167
protected function addDailyMotionForm ( $ builder ) { $ builder -> add ( 'dailymotionVideoId' , 'oo_video' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.video_id' , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionWidth' , 'text' , array ( 'empty_data' => '480' , 'label' => 'open_orchestra_backoffice.block.video.dailymotion.width' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionHeight' , 'text' , array ( 'empty_data' => '269' , 'label' => 'open_orchestra_backoffice.block.video.dailymotion.height' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionQuality' , 'choice' , array ( 'choices' => array ( '240' => '240' , '380' => '380' , '480' => '480' , '720' => '720' , '1080' => '1080' ) , 'label' => 'open_orchestra_backoffice.block.video.dailymotion.quality' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionAutoplay' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.autoplay' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionInfo' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.info' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionRelated' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.related' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionChromeless' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.chromeless' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionLogo' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.logo' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionBackground' , 'oo_color_picker' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.background' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionForeground' , 'oo_color_picker' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.foreground' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) -> add ( 'dailymotionHighlight' , 'oo_color_picker' , array ( 'label' => 'open_orchestra_backoffice.block.video.dailymotion.highlight' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'dailymotion' ) ) ) ; }
Add to the video form the dailymotion part
34,168
protected function addVimeoForm ( $ builder ) { $ builder -> add ( 'vimeoVideoId' , 'oo_video' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.video_id' , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoWidth' , 'text' , array ( 'empty_data' => '480' , 'label' => 'open_orchestra_backoffice.block.video.vimeo.width' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoHeight' , 'text' , array ( 'empty_data' => '269' , 'label' => 'open_orchestra_backoffice.block.video.vimeo.height' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoColor' , 'oo_color_picker' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.color' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' , 'class' => 'colorpicker' ) ) ) -> add ( 'vimeoAutoplay' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.autoplay' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoFullscreen' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.fullscreen' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoTitle' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.title_video' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoByline' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.byline' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoPortrait' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.portrait' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoLoop' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.loop' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) -> add ( 'vimeoBadge' , 'checkbox' , array ( 'label' => 'open_orchestra_backoffice.block.video.vimeo.badge' , 'required' => false , 'group_id' => 'data' , 'sub_group_id' => 'content' , 'attr' => array ( 'data-video-type' => 'vimeo' ) ) ) ; }
Add to the video form the vimeo part
34,169
public function find ( $ name ) { if ( strpos ( $ name , '::' ) !== false ) { return $ this -> findNamedPathView ( $ name ) ; } return $ this -> findInPaths ( $ name , $ this -> paths ) ; }
Find a correct path file
34,170
public function get ( $ alias , $ fallback = '_michaels_no_fallback' ) { $ link = $ this -> getIfExists ( "$alias" ) ; if ( is_string ( $ link ) && strpos ( $ link , '_michaels_link_' ) !== false ) { return $ this -> get ( str_replace ( '_michaels_link_' , '' , $ link ) ) ; } $ shared = $ this -> getIfExists ( "_singletons.$alias" ) ; if ( $ shared instanceof NoItemFoundMessage ) { return $ this -> produceDependency ( $ alias , $ fallback ) ; } else { if ( is_object ( $ shared ) ) { return $ shared ; } else { $ object = $ this -> produceDependency ( $ alias , $ fallback ) ; $ this -> set ( "_singletons.$alias" , $ object ) ; return $ object ; } } }
Returns the request object with all dependencies
34,171
public function add ( $ alias , $ factory = null , array $ declared = null ) { if ( is_array ( $ alias ) ) { $ links = $ alias ; $ alias = $ alias [ 0 ] ; unset ( $ links [ 0 ] ) ; } $ this -> set ( "$alias" , $ factory ) ; if ( $ declared ) { $ this -> set ( "_declarations.$alias" , $ declared ) ; } if ( ! empty ( $ links ) ) { foreach ( $ links as $ link ) { $ this -> set ( "$link" , "_michaels_link_$alias" ) ; } } return $ this ; }
Adds a dependency to the manager
34,172
protected function produceDependency ( $ alias , $ fallback = '_michaels_no_fallback' ) { $ factory = $ this -> getIfExists ( "$alias" ) ; if ( $ factory instanceof NoItemFoundMessage ) { if ( $ fallback !== '_michaels_no_fallback' ) { return $ fallback ; } elseif ( class_exists ( $ alias ) ) { return new $ alias ; } else { throw new ItemNotFoundException ( "$alias not found" ) ; } } $ declared = $ this -> getIfExists ( "_declarations.$alias" ) ; $ dependencies = [ ] ; if ( ! $ declared instanceof NoItemFoundMessage ) { $ dependencies = array_map ( function ( & $ value ) use ( $ alias ) { if ( is_string ( $ value ) && $ this -> exists ( "$alias" ) ) { return $ this -> get ( $ value ) ; } return $ value ; } , $ declared ) ; } if ( $ factory instanceof IocContainerInterface ) { $ object = $ factory -> get ( $ alias ) ; } elseif ( is_string ( $ factory ) ) { $ class = new \ ReflectionClass ( $ factory ) ; $ object = $ class -> newInstanceArgs ( $ dependencies ) ; } elseif ( is_callable ( $ factory ) ) { array_unshift ( $ dependencies , $ this ) ; $ object = call_user_func_array ( $ factory , $ dependencies ) ; } elseif ( is_object ( $ factory ) ) { $ object = $ factory ; if ( method_exists ( $ object , "needs" ) ) { call_user_func_array ( [ $ object , 'needs' ] , $ dependencies ) ; } } else { throw new \ Exception ( "`get()` can only return from strings, callables, or objects" ) ; } $ pipeline = $ this -> getIfExists ( "_pipelines.$alias" ) ; if ( ! $ pipeline instanceof NoItemFoundMessage ) { $ object = $ pipeline ( $ object , $ this ) ; } return $ object ; }
Produces the object from an alias
34,173
protected function initialize ( array $ splFileInfoObjects = [ ] ) { if ( ! empty ( $ splFileInfoObjects ) ) { foreach ( $ splFileInfoObjects as $ object ) { array_push ( $ this -> fileObjects , $ this -> createSplFileInfoObject ( $ object ) ) ; } } }
Set up the bag with a proper array of SplFileInfo objects
34,174
protected function createSplFileInfoObject ( $ entity ) { if ( $ entity instanceof \ SplFileInfo ) { return $ entity ; } if ( is_string ( $ entity ) && file_exists ( $ entity ) ) { return new \ SplFileInfo ( $ entity ) ; } $ isArray = is_array ( $ entity ) ; if ( $ isArray && $ entity [ 0 ] instanceof \ SplFileInfo ) { return $ entity ; } if ( $ isArray && is_string ( $ entity [ 0 ] ) && file_exists ( $ entity [ 0 ] ) ) { return [ new \ SplFileInfo ( $ entity [ 0 ] ) , $ entity [ 1 ] ] ; } throw new BadFileInfoObjectException ( 'The input array does not hold proper SplFileInfo objects.' ) ; }
Check for an \ SplFileInfo object or a custom namespaces object
34,175
public function send ( MessageInterface $ message , $ skipErrors = true ) { if ( count ( $ message -> getRecipient ( ) ) > self :: MAX_RECIPIENS ) { throw new ConfigurationException ( 'Too many recipiens. For SerwerSms gateway limit is ' . self :: MAX_RECIPIENS ) ; } $ client = $ this -> getClient ( ) ; $ extraParams = $ this -> getParam ( 'extra' ) ; if ( ! isset ( $ extraParams [ 'details' ] ) || $ extraParams [ 'details' ] === false ) { $ extraParams [ 'details' ] = true ; } try { $ response = $ client -> messages -> sendSms ( $ message -> getRecipients ( ) , $ message -> getText ( ) , $ this -> getParam ( 'sender' ) , $ extraParams ) ; if ( ( int ) $ response -> unsent > 0 ) { foreach ( $ response -> items as $ item ) { if ( $ item -> status === 'unsent' ) { $ this -> addError ( new SendingError ( $ item -> phone , $ item -> error_code , $ item -> error_message . 'id:' . $ item -> id ) ) ; if ( ! $ skipErrors ) { throw new \ RuntimeException ( $ item -> error_message , $ item -> error_code ) ; } } } } } catch ( Exception $ e ) { $ this -> addError ( new SendingError ( '' , $ e -> getCode ( ) , $ e -> getMessage ( ) ) ) ; if ( ! $ skipErrors ) { throw new \ RuntimeException ( $ e -> getMessage ( ) ) ; } } return $ this -> getErrors ( ) -> count ( ) === 0 ; }
Send message through SerwerSms gateway
34,176
public function findFiles ( InputInterface $ input , array $ exclude = [ ] ) : array { $ this -> exclude = $ exclude ; if ( substr ( $ this -> basePath , - 1 ) != '/' ) { $ this -> basePath .= '/' ; } $ fileOption = $ input -> getOption ( 'file' ) ; if ( $ fileOption !== null ) { $ file = $ this -> basePath . TypeCast :: castString ( $ fileOption ) ; $ files = [ new SplFileInfo ( $ file ) ] ; } else { $ files = [ ] ; $ this -> processDirectory ( '' , $ files ) ; } return $ files ; }
Find all files .
34,177
protected function processDirectory ( string $ path = '' , array & $ worklist = [ ] ) : void { $ dir = new DirectoryIterator ( $ this -> basePath . $ path ) ; foreach ( $ dir as $ item ) { if ( $ item -> isDot ( ) ) { continue ; } $ itemPath = $ path . $ item -> getFilename ( ) ; if ( $ this -> exclude ( $ itemPath ) ) { continue ; } if ( $ item -> isFile ( ) && $ item -> getExtension ( ) == 'php' ) { $ worklist [ ] = $ item -> getFileInfo ( ) ; } if ( $ item -> isDir ( ) ) { $ this -> processDirectory ( $ itemPath . '/' , $ worklist ) ; } } }
Iterate through a directory and check all of the PHP files within it .
34,178
protected function exclude ( string $ path ) : bool { foreach ( $ this -> exclude as $ pattern ) { $ replacements = [ '\\,' => ',' , '*' => '.*' , ] ; $ pattern = strtr ( $ pattern , $ replacements ) ; if ( preg_match ( "|{$pattern}|i" , $ path ) === 1 ) { return true ; } } return false ; }
Check if path should be excluded .
34,179
public static function detect ( ) { $ file = Composer :: getRootPath ( '/app/config/env.php' ) ; if ( is_file ( $ file ) ) { $ config = include $ file ; } else { $ config = include dirname ( __DIR__ ) . '/../config/env.php' ; } if ( defined ( 'ZE_ENV' ) ) { return ZE_ENV ; } elseif ( isset ( $ _SERVER [ 'ZE_ENV' ] ) ) { define ( 'ZE_ENV' , $ _SERVER [ 'ZE_ENV' ] ) ; return ZE_ENV ; } elseif ( is_array ( $ config ) ) { $ env = 'production' ; foreach ( $ config as $ key => $ value ) { if ( is_callable ( $ value ) && $ value instanceof \ Closure && $ value ( ) ) { $ env = $ key ; } elseif ( is_string ( $ value ) ) { if ( preg_match ( '/\//i' , $ value ) ) { if ( preg_match ( $ value , getenv ( 'HTTP_HOST' ) ) ) { $ env = $ key ; } } else { if ( preg_match ( '/' . $ value . '/i' , getenv ( 'HTTP_HOST' ) ) ) { $ env = $ key ; } } } } define ( 'ZE_ENV' , $ env ) ; return ZE_ENV ; } }
Smarter way to get config env
34,180
public static function level ( ) { if ( defined ( 'ZE_LEVEL_ENV' ) ) { return ZE_LEVEL_ENV ; } else { $ env = self :: detect ( ) ; switch ( $ env ) { case 'console' : $ level_env = 0 ; break ; case 'local' : $ level_env = 1 ; break ; case 'dev' : $ level_env = 2 ; break ; case 'demo' : $ level_env = 3 ; break ; default : $ level_env = 4 ; break ; } define ( 'ZE_LEVEL_ENV' , $ level_env ) ; } return ZE_LEVEL_ENV ; }
Define level environment
34,181
public static function arrayToRegex ( $ array ) { if ( isset ( $ array ) ) { foreach ( $ array as $ k => $ item ) { if ( is_string ( $ item ) ) { $ array [ $ k ] = $ item ; } else { $ array [ $ k ] = "\"" . $ item . "\"" ; } } } return implode ( '|' , $ array ) ; }
Tranform an array to a valid Regex format
34,182
public static function prepareParams ( array $ param ) { $ fillable = static :: getInstance ( ) -> getFillables ( ) ; foreach ( $ param as $ key => $ value ) { if ( ! in_array ( $ key , $ fillable ) ) { unset ( $ param [ $ key ] ) ; } elseif ( ! $ value ) { unset ( $ param [ $ key ] ) ; } } return $ param ; }
Prepare input for query
34,183
public static function getFillables ( ) { $ instance = static :: getInstance ( ) ; $ fillable = $ instance -> fillable ; if ( $ fillable == array ( '*' ) || ! $ fillable ) { $ instance -> fillable = array_keys ( $ instance -> getStructure ( ) ) ; } return $ instance -> fillable ; }
Get fillables columns from model helpers
34,184
public static function getRules ( ) { $ instance = static :: getInstance ( ) ; $ fillables = $ instance -> getFillables ( ) ; $ structure = $ instance -> getStructure ( ) ; $ rules = $ instance -> rules ; if ( ! $ rules ) { $ rules = [ ] ; foreach ( $ structure as $ key => $ column ) { $ rules [ $ key ] = '' ; } } return $ rules ; }
Get Rules from Model
34,185
public function build ( ) { $ headers = array ( ) ; foreach ( get_object_vars ( $ this ) as $ header => $ value ) { $ headers [ ] = $ header . ": " . ( string ) $ value ; } return $ headers ; }
Build the headers
34,186
public function parse ( $ headers ) { $ lines = preg_split ( "/(\r|\n)+/" , $ headers , - 1 , PREG_SPLIT_NO_EMPTY ) ; array_shift ( $ lines ) ; foreach ( $ lines as $ line ) { list ( $ name , $ value ) = explode ( ':' , $ line , 2 ) ; $ this -> { strtolower ( trim ( $ name ) ) } = trim ( $ value ) ; } }
Parse a header string into the object
34,187
public function reset ( ) { $ headers = array_keys ( get_object_vars ( $ this ) ) ; foreach ( $ headers as $ key ) { $ this -> offsetUnset ( $ key ) ; } }
Reset the headers content .
34,188
public function offsetGet ( $ offset ) { if ( isset ( $ this -> { $ name = strtolower ( $ offset ) } ) ) { return $ this -> $ name ; } return null ; }
Return an offset
34,189
public function getIndex ( Request $ request , $ userId ) { $ user = User :: findOrFail ( $ userId ) ; $ items = $ user -> items ( ) -> where ( 'start_date' , '<=' , time ( ) ) -> where ( 'end_date' , '>=' , time ( ) ) -> orderBy ( 'end_date' , 'asc' ) -> paginate ( ) ; return view ( 'mustard::user.profile' , [ 'user' => $ user , 'items' => $ items , 'feedbacks' => mustard_loaded ( 'feedback' ) ? $ user -> feedbackReceived ( ) -> orderBy ( 'placed' ) -> take ( 3 ) -> get ( ) : new Collection ( ) , ] ) ; }
Return the user profile view .
34,190
public function registerCommands ( ) { foreach ( $ this -> commands as $ name => $ class ) { $ dotName = str_replace ( ':' , '.' , $ name ) ; $ this -> app [ 'command.' . $ dotName ] = $ this -> app -> share ( function ( ) use ( $ class ) { $ commandClassName = $ class ; return new $ commandClassName ( ) ; } ) ; $ this -> commands ( 'command.' . $ dotName ) ; } }
Register commands helper
34,191
public function registerFacades ( ) { AliasLoader :: getInstance ( $ this -> facades ) ; foreach ( $ this -> facades as $ alias => $ name ) { AliasLoader :: getInstance ( ) -> alias ( $ alias , $ name ) ; } }
Register facades helpers
34,192
public function requireScopes ( ) { $ scopes = func_get_args ( ) ; $ has_scopes = call_user_func_array ( [ $ this , 'hasOneOfScopes' ] , $ scopes ) ; if ( ! $ has_scopes ) { throw new AccessDeniedException ; } return true ; }
Require a set of scopes or throw exception
34,193
public function applyRepositoryFilters ( array $ filters , Repository $ repository ) { $ repository -> setFilters ( array_merge ( $ repository -> getFilters ( ) , $ filters ) ) ; }
Merge new filters with the existing repository filters
34,194
public function offsetExists ( $ key ) { if ( isset ( $ this -> data [ $ key ] ) ) { return new self ( $ this -> data [ $ key ] ) ; } return false ; }
Determine if a given offset exists
34,195
public function isGranted ( $ action , $ entity , array $ parameters = array ( ) ) { $ entityType = defined ( get_class ( $ entity ) . '::ENTITY_TYPE' ) ? $ entity :: ENTITY_TYPE : null ; if ( ! is_null ( $ entityType ) && array_key_exists ( $ entityType , $ this -> strategies ) && $ this -> strategies [ $ entityType ] -> support ( $ action ) ) { return $ this -> strategies [ $ entityType ] -> isGranted ( $ action , $ entity , $ parameters ) ; } return true ; }
Check if object is granted
34,196
public function isThrottled ( $ identity ) { $ identity = $ this -> parseIdentity ( $ identity ) ; $ count = $ this -> countThrottle ( $ identity , 0 ) ; return $ count >= config ( 'store.throttle_limit' , 10 ) ; }
Tells if the given identity has reached the throttle_limit .
34,197
protected function countThrottle ( $ identityString , $ increments = 1 ) { $ count = app ( 'cache' ) -> get ( 'login_throttling:' . md5 ( $ identityString ) , 0 ) ; $ count = $ count + $ increments ; $ ttl = config ( 'store.throttle_time_period' ) ; app ( 'cache' ) -> put ( 'login_throttling:' . md5 ( $ identityString ) , $ count , $ ttl ) ; return $ count ; }
Increments the count for the given string by one stores it into cache and returns the current value for that identity .
34,198
private function setColor ( $ color ) { if ( ! isset ( self :: $ colors [ $ color ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid foreground color specified: "%s". Expected one of (%s)' , $ color , implode ( ', ' , array_keys ( self :: $ colors ) ) ) ) ; } $ this -> color = self :: $ colors [ $ color ] ; }
Sets the team color .
34,199
private function setEye ( $ eye ) { if ( ! is_string ( $ eye ) || strlen ( $ eye ) !== 1 ) { throw new \ InvalidArgumentException ( 'Eye must be a one character string' ) ; } $ this -> eye = $ eye ; }
Sets the team eye .