idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
45,700
public function get ( $ id ) { try { $ em = $ this -> entityManager -> getDoctrineEntityManager ( ) ; $ accessEntity = $ em -> getRepository ( $ this -> getEntityClass ( ) ) -> findOneBy ( array ( 'id' => $ id , ) ) ; if ( $ accessEntity !== null ) { return $ accessEntity ; } return false ; } catch ( \ Exception $ e ) { throw new Exception ( 'Cannot load the entity from the database for the given id "' . $ id . '".' , 0 , $ e ) ; } }
Returns the entity object for the given id
45,701
public function add ( EntityInterface $ entity ) { if ( ! is_a ( $ entity , $ this -> getEntityClass ( ) ) ) { throw new Exception ( 'The given entity (' . get_class ( $ entity ) . ') is not compatible with this data source (' . self :: class . '.' ) ; } try { $ em = $ this -> entityManager -> getDoctrineEntityManager ( ) ; $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; return $ entity -> getId ( ) ; } catch ( \ Exception $ e ) { throw new Exception ( 'Cannot add the entity "' . $ entity . '".' , 0 , $ e ) ; } }
Adds an entity . Returns the id of the entity or false if the entity can not inserted .
45,702
public function update ( EntityInterface $ entity ) { if ( ! is_a ( $ entity , $ this -> getEntityClass ( ) ) ) { throw new Exception ( 'The given entity (' . get_class ( $ entity ) . ') is not compatible with this data source (' . self :: class . '.' ) ; } try { $ em = $ this -> entityManager -> getDoctrineEntityManager ( ) ; $ em -> flush ( ) ; return true ; } catch ( \ Exception $ e ) { throw new Exception ( 'Cannot update the entity"' . $ entity . '".' , 0 , $ e ) ; } }
Updates the entity . Returns true if everything worked as excepted or false if the update didn t worked .
45,703
protected function buildTree ( array $ simpleTree , $ tree = [ ] ) { foreach ( $ simpleTree as $ item ) { if ( ! isset ( $ this -> collection [ $ item [ 'id' ] ] ) ) { continue ; } $ content = $ this -> collection [ $ item [ 'id' ] ] ; unset ( $ this -> collection [ $ item [ 'id' ] ] ) ; if ( isset ( $ item [ '__children' ] ) && count ( $ item [ '__children' ] ) ) { $ content [ '__children' ] = $ this -> buildTree ( $ item [ '__children' ] ) ; } else { $ content [ '__children' ] = [ ] ; } $ tree [ ] = $ content ; } return $ tree ; }
Build the tree from the simpletree and the collection
45,704
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ io = new SymfonyStyle ( $ input , $ output ) ; if ( ! $ this -> metadata ) { try { $ this -> metadata = $ this -> retrieveMetadatas ( $ input -> getArgument ( 'name' ) ) ; } catch ( \ Exception $ e ) { $ io -> error ( $ e -> getMessage ( ) ) ; return ; } } $ metadatas = $ this -> metadata -> getMetadata ( ) ; $ namespace = str_replace ( '\\Entity' , '' , $ this -> metadata -> getNamespace ( ) ) ; $ path = $ this -> metadata -> getPath ( ) ; $ basePath = sprintf ( '%s/%s' , $ path , str_replace ( '\\' , '/' , $ namespace ) ) ; $ appDir = $ this -> getContainer ( ) -> getParameter ( 'kernel.root_dir' ) ; $ adminGenerator = new AdminGenerator ( $ appDir ) ; $ managerGenerator = new ManagerGenerator ( $ appDir ) ; $ adminCtlGenerator = new AdminControllerGenerator ( $ appDir ) ; $ servicesGenerator = new ServicesGenerator ( $ appDir ) ; $ transGenerator = new TranslationsGenerator ( $ appDir ) ; foreach ( $ metadatas as $ metadata ) { $ entityName = $ this -> getEntityNameFromMetadata ( $ metadata ) ; $ output -> writeln ( '' ) ; $ output -> writeln ( sprintf ( 'Generate files for entity %s' , $ entityName ) ) ; $ output -> writeln ( $ adminGenerator -> generate ( $ namespace , $ basePath , $ metadata ) ) ; $ output -> writeln ( $ managerGenerator -> generate ( $ namespace , $ basePath , $ metadata ) ) ; $ output -> writeln ( $ adminCtlGenerator -> generate ( $ namespace , $ basePath , $ metadata ) ) ; $ transGenerator -> setBundleName ( $ this -> getBundleNameFromEntity ( $ metadata -> rootEntityName ) ) ; $ output -> writeln ( $ transGenerator -> generate ( $ namespace , $ basePath , $ metadata ) ) ; $ servicesGenerator -> setBundleName ( $ this -> getBundleNameFromEntity ( $ metadata -> rootEntityName ) ) ; $ output -> writeln ( $ servicesGenerator -> generate ( $ namespace , $ basePath , $ metadata ) ) ; } }
execute command .
45,705
public function execute ( $ className ) { $ this -> className = $ className ; $ rawRequest = file_get_contents ( 'php://input' ) ; $ request = json_decode ( $ rawRequest , true ) ; if ( $ request == false ) { throw new MRPCJsonServerException ( sprintf ( 'Invalid body (%s).' , $ rawRequest ) ) ; } if ( $ request [ 'jsonrpc' ] != '2.0' ) { throw new MRPCJsonServerException ( sprintf ( 'The request does not respect the 2.0 specification.' ) ) ; } $ this -> request = new MRPCJsonRequest ( ) ; $ this -> request -> setMethod ( $ request [ 'method' ] ) -> setParams ( $ request [ 'params' ] ) -> setId ( $ request [ 'id' ] ) ; $ callResponse = call_user_func ( array ( $ this , $ this -> request -> getMethod ( ) ) , $ this -> request -> getParams ( ) ) ; if ( $ callResponse === false ) { throw new MRPCJsonServerException ( 'Invalid method name.' ) ; } }
Reads the request and run the web method .
45,706
public static function autorun ( ) { $ classes = array_reverse ( get_declared_classes ( ) ) ; foreach ( $ classes as $ class ) { $ type = new \ ReflectionClass ( $ class ) ; $ abstract = $ type -> isAbstract ( ) ; if ( is_subclass_of ( $ class , MRPCJsonWebService :: class ) === false || $ abstract === true ) { continue ; } $ webService = new $ class ( ) ; if ( $ _SERVER [ 'QUERY_STRING' ] == 'definition' ) { $ definition = new MRPCJsonWebServiceDefinition ( $ class ) ; $ webService -> getHttpResponse ( ) -> setContentType ( ContentType :: TEXT_HTML ) ; $ webService -> getHttpResponse ( ) -> setOutput ( ( string ) $ definition ) ; } else { $ webService -> getHttpResponse ( ) -> setContentType ( ContentType :: APPLICATION_JSON ) ; try { $ webService -> execute ( $ class ) ; $ webService -> getResponse ( ) -> setId ( $ webService -> getRequest ( ) -> getId ( ) ) ; } catch ( MRPCJsonServerException $ ex ) { $ error = new MRPCJsonError ( ) ; $ error -> setCode ( - 1 ) ; $ error -> setMessage ( $ ex -> getMessage ( ) ) ; $ webService -> response = new MRPCJsonResponse ( ) ; $ webService -> response -> setError ( $ error ) ; } $ webService -> getHttpResponse ( ) -> setOutput ( $ webService -> getResponse ( ) -> toJSON ( ) ) ; } return $ webService ; } return null ; }
Run the instance of the web service .
45,707
public function update ( string $ name , string $ title = "" , bool $ completable = false ) : Prop { $ row = self :: getEventItem ( $ name ) ; if ( ! $ row ) { throw new NotFoundException ( "Event '{$name}' not found" ) ; } $ this -> permissible ( $ row -> module_id , $ name ) ; $ title = trim ( $ title ) ; if ( strlen ( $ title ) < 1 ) { $ title = $ name . " event" ; } $ prop = new Prop ( [ "action" => "update" , "updated" => false ] ) ; if ( $ title === $ row -> title && $ completable === $ row -> completable ) { return $ prop ; } $ event = new EventUpdateDriverEvent ( $ this , $ name , $ title , $ completable ) ; $ dispatcher = EventManager :: dispatcher ( $ event -> getName ( ) ) ; $ dispatcher -> dispatch ( $ event ) ; $ prop -> set ( "updated" , \ DB :: table ( "events" ) -> whereId ( $ row -> id ) -> update ( compact ( 'title' , 'completable' ) ) > 0 ) ; $ prop -> get ( "updated" ) && $ this -> addLogDebug ( Text :: createInstance ( "The %s event is successfully updated" , $ name ) ) ; $ dispatcher -> complete ( $ prop ) ; return $ prop ; }
Update event data
45,708
public static function hasName ( $ name , $ module_id = null ) : bool { if ( ! self :: isValidName ( $ name ) ) { return false ; } $ builder = \ DB :: table ( "events" ) -> where ( "name" , $ name ) ; if ( is_numeric ( $ module_id ) ) { $ builder -> where ( "module_id" , ( int ) $ module_id ) ; } return $ builder -> count ( [ "id" ] ) > 0 ; }
Config name is exists
45,709
public static function isValidName ( $ name ) : bool { $ len = strlen ( $ name ) ; if ( $ len < 5 || ! preg_match ( '/^on[A-Z][a-zA-Z]*$/' , $ name ) ) { return false ; } return $ len < 256 ; }
Validate config name
45,710
public function bindParam ( $ tag , & $ param , $ type = DB :: PARAM_AUTO ) { if ( ! is_int ( $ tag ) and ctype_digit ( $ tag ) ) $ tag = intval ( $ tag ) ; elseif ( is_string ( $ tag ) ) { if ( ':' != substr ( $ tag , 0 , 1 ) ) $ tag = ":$tag" ; } else return false ; $ this -> parameters [ $ tag ] = array ( 'param' => & $ param , 'type' => $ type ) ; return true ; }
Binds parameter to statement
45,711
private static function processContext ( $ message , array $ context = array ( ) ) { $ replace = array ( ) ; foreach ( $ context as $ key => $ value ) { $ templated = "{" . $ key . "}" ; $ replace [ $ templated ] = $ value ; } if ( self :: checkContextException ( $ context ) ) { $ exception = $ context [ "exception" ] ; $ replace [ "{line}" ] = $ exception -> getLine ( ) ; $ replace [ "{file}" ] = $ exception -> getFile ( ) ; $ replace [ "{message}" ] = $ exception -> getMessage ( ) ; } return strtr ( $ message , $ replace ) ; }
Processes context as supplied by the log method replacing templated strings with data from the context array or processing exception data via checkContextException .
45,712
private static function checkContextException ( array $ context = array ( ) ) { if ( isset ( $ context [ "exception" ] ) ) { $ includes_exception = $ context [ "exception" ] instanceof \ Exception ; } else { $ includes_exception = false ; } return $ includes_exception ; }
Determines whether a context array contains an Exception .
45,713
public function rulesets ( $ ruleSetFileNames ) { if ( ! is_array ( $ ruleSetFileNames ) ) { $ ruleSetFileNames = [ $ ruleSetFileNames ] ; } $ this -> rulesets = array_unique ( array_merge ( $ this -> rulesets , $ ruleSetFileNames ) ) ; return $ this ; }
Sets the rule - sets .
45,714
public function allowedFileExtensions ( $ fileExtensions ) { if ( ! is_array ( $ fileExtensions ) ) { $ fileExtensions = [ $ fileExtensions ] ; } $ this -> extensions = array_unique ( array_merge ( $ this -> extensions , $ fileExtensions ) ) ; return $ this ; }
Sets a list of filename extensions for valid php source code files .
45,715
public function ignorePatterns ( $ ignorePatterns ) { if ( ! is_array ( $ ignorePatterns ) ) { $ ignorePatterns = [ $ ignorePatterns ] ; } $ this -> ignorePatterns = array_unique ( array_merge ( $ this -> ignorePatterns , $ ignorePatterns ) ) ; return $ this ; }
Sets a list of ignore patterns that is used to exclude directories from the source analysis .
45,716
public function isValidRequest ( $ headerOnly = true , $ accessToken = null ) { $ accessTokenString = ( $ accessToken !== null ) ? $ accessToken : $ this -> determineAccessToken ( $ headerOnly ) ; $ this -> accessToken = $ this -> getAccessTokenStorage ( ) -> get ( $ accessTokenString ) ; if ( ! $ this -> accessToken instanceof AccessTokenEntity ) { throw new AccessDeniedException ( ) ; } if ( $ this -> accessToken -> isExpired ( ) === true ) { throw new AccessDeniedException ( ) ; } \ Illuminate \ Support \ Facades \ DB :: table ( 'oauth_access_tokens' ) -> where ( 'id' , $ accessTokenString ) -> update ( [ 'expire_time' => time ( ) + 30 ] ) ; return true ; }
Checks if the access token is valid or not
45,717
public function determineAccessToken ( $ headerOnly = false ) { if ( ! empty ( $ this -> getRequest ( ) -> headers -> get ( 'Authorization' ) ) ) { $ accessToken = $ this -> getTokenType ( ) -> determineAccessTokenInHeader ( $ this -> getRequest ( ) ) ; } elseif ( $ headerOnly === false && ( ! $ this -> getTokenType ( ) instanceof MAC ) ) { $ accessToken = ( $ this -> getRequest ( ) -> server -> get ( 'REQUEST_METHOD' ) === 'GET' ) ? $ this -> getRequest ( ) -> query -> get ( $ this -> tokenKey ) : $ this -> getRequest ( ) -> request -> get ( $ this -> tokenKey ) ; } if ( empty ( $ accessToken ) ) { throw new InvalidRequestException ( 'access token' ) ; } return $ accessToken ; }
Reads in the access token from the headers
45,718
public function indexAction ( ) { $ models = $ this -> getAllModels ( ) ; foreach ( $ models as $ model ) { $ this -> checkTable ( new $ model [ 'namespace' ] ) ; } }
Synchronize all table fields
45,719
private function checkTable ( $ modelObj ) { if ( ! method_exists ( $ modelObj , 'table' ) ) { return false ; } $ tableName = $ modelObj -> table ( ) ; $ existTable = PdoDriver :: getInstance ( ) -> tableExists ( $ tableName ) ; if ( ! $ existTable ) { $ this -> createTable ( $ tableName , $ modelObj -> getFields ( ) ) ; CliManager :: getMessage ( 'Created table ' . $ tableName ) ; } PdoDriver :: getInstance ( ) -> query ( 'SHOW COLUMNS FROM ' . $ tableName ) ; $ dbFields = PdoDriver :: getInstance ( ) -> selectAll ( ) ; $ modelFieldNames = [ ] ; foreach ( $ modelObj -> getFields ( ) as $ modelField ) { $ modelFieldNames [ ] = $ modelField -> identifier ( ) ; } $ dbFieldNames = [ ] ; foreach ( $ dbFields as $ dbField ) { if ( ! in_array ( $ dbField -> Field , $ modelFieldNames ) ) { echo " --- Old field " . CliManager :: setTextColor ( $ dbField -> Field , 'yellow' ) . " in table " . CliManager :: setTextColor ( $ modelObj -> table ( ) , 'green' ) . " --- \n\r" ; } $ dbFieldNames [ ] = $ dbField -> Field ; } foreach ( $ modelObj -> getFields ( ) as $ key => $ modelField ) { if ( ! in_array ( $ modelField -> identifier ( ) , $ dbFieldNames ) ) { $ previousField = false ; if ( isset ( $ modelObj -> getFields ( ) [ $ key - 1 ] ) ) { $ previousField = $ modelObj -> getFields ( ) [ $ key - 1 ] ; } $ this -> createField ( $ tableName , $ modelField , $ previousField ) ; echo CliManager :: setTextColor ( " --- Add New field " . $ modelField -> identifier ( ) . " in table " . $ modelObj -> table ( ) , 'green' ) . " --- \n\r" ; } } }
Check Table fields
45,720
private function getAllModels ( ) { $ modules = Safan :: handler ( ) -> getModules ( ) ; $ modelClasses = [ ] ; foreach ( $ modules as $ moduleName => $ modulePath ) { $ modelsPath = APP_BASE_PATH . DS . $ modulePath . DS . 'Models' ; $ modelFiles = [ ] ; if ( is_dir ( $ modelsPath ) ) { $ modelFiles = scandir ( $ modelsPath ) ; } foreach ( $ modelFiles as $ modelFile ) { if ( $ modelFile != '.' && $ modelFile != '..' && is_dir ( $ modelsPath . DS . $ modelFile ) ) { $ subModelFiles = scandir ( $ modelsPath . DS . $ modelFile ) ; foreach ( $ subModelFiles as $ subModelFile ) { if ( $ subModelFile != '.' && $ subModelFile != '..' && is_file ( $ modelsPath . DS . $ modelFile . DS . $ subModelFile ) ) { $ subModelName = substr ( $ subModelFile , 0 , - 4 ) ; $ modelClasses [ ] = [ 'name' => $ subModelName , 'namespace' => '\\' . $ moduleName . '\\Models\\' . $ modelFile . '\\' . $ subModelName , 'file' => $ modelsPath . DS . $ modelFile . DS . $ subModelFile ] ; } } } elseif ( $ modelFile != '.' && $ modelFile != '..' && is_file ( $ modelsPath . DS . $ modelFile ) ) { $ modelName = substr ( $ modelFile , 0 , - 4 ) ; $ modelClasses [ ] = [ 'name' => $ modelName , 'namespace' => '\\' . $ moduleName . '\\Models\\' . $ modelName , 'file' => $ modelsPath . DS . $ modelFile ] ; } } } return $ modelClasses ; }
Return all Model Class names
45,721
protected function quoteAlias ( $ alias , array $ settings ) { if ( is_int ( $ alias ) ) { return '' ; } else { $ prefix = $ settings [ 'quotePrefix' ] ; $ suffix = $ settings [ 'quoteSuffix' ] ; return ' AS ' . $ this -> quoteSpace ( $ alias , $ prefix , $ suffix ) ; } }
Quote an alias if not an int
45,722
protected function & getClause ( $ clauseName ) { if ( empty ( $ clauseName ) ) { return $ this -> clause ; } else { if ( ! isset ( $ this -> clause [ $ clauseName ] ) ) { $ this -> clause [ $ clauseName ] = [ ] ; } return $ this -> clause [ $ clauseName ] ; } }
Return specific clause part
45,723
protected function processValue ( $ value , array $ settings , $ between = false ) { if ( is_object ( $ value ) ) { return $ this -> quoteObject ( $ value , $ settings ) ; } elseif ( is_array ( $ value ) ) { return $ this -> processArrayValue ( $ value , $ settings , $ between ) ; } else { return $ this -> processScalarValue ( $ value ) ; } }
Process value part in the clause
45,724
protected function processArrayValue ( array $ value , array $ settings , $ between = false ) { if ( $ between ) { $ v1 = $ this -> processValue ( $ value [ 0 ] , $ settings ) ; $ v2 = $ this -> processValue ( $ value [ 1 ] , $ settings ) ; return $ v1 . ' AND ' . $ v2 ; } else { $ result = [ ] ; foreach ( $ value as $ val ) { $ result [ ] = $ this -> processValue ( $ val , $ settings ) ; } return '(' . join ( ', ' , $ result ) . ')' ; } }
Process value array
45,725
protected function processScalarValue ( $ value ) { if ( ClauseInterface :: NO_VALUE == $ value ) { return '?' ; } elseif ( is_null ( $ value ) || is_bool ( $ value ) ) { return strtoupper ( var_export ( $ value , true ) ) ; } else { return $ this -> getBuilder ( ) -> getParameter ( ) -> getPlaceholder ( $ value ) ; } }
Process scalar value
45,726
protected function joinClause ( $ prefix , $ seperator , array $ clause , array $ settings ) { if ( empty ( $ clause ) ) { return '' ; } else { $ sepr = $ settings [ 'seperator' ] ; $ join = $ settings [ 'join' ] ; $ pref = empty ( $ prefix ) ? $ join : ( $ sepr . $ prefix . $ join ) ; return $ pref . join ( $ seperator . $ join , $ clause ) ; } }
Join a clause with prefix and its parts
45,727
protected function buildClause ( $ clauseName , $ clausePrefix , array $ settings , array $ clauseParts = [ ] ) { $ clause = & $ this -> getClause ( $ clauseName ) ; foreach ( $ clause as $ alias => $ field ) { $ part = $ this -> quoteItem ( $ field [ 0 ] , $ settings , $ field [ 1 ] ) . $ this -> quoteAlias ( $ alias , $ settings ) . ( isset ( $ field [ 2 ] ) ? ( ' ' . $ field [ 2 ] ) : '' ) ; $ clauseParts [ ] = $ part ; } return $ this -> joinClause ( $ clausePrefix , ',' , $ clauseParts , $ settings ) ; }
Build a generic clause
45,728
public static function typed ( string $ type , iterable $ input = [ ] ) : Deque { $ resolver = Resolver :: typed ( $ type ) ; return new static ( $ input , $ resolver ) ; }
Deque named constructor .
45,729
public function link ( $ target , $ caption = null , $ attributes = array ( ) ) { if ( is_object ( $ target ) ) { $ target = Url :: instance ( ) -> show ( $ target ) ; } $ link = new \ HtmlObject \ Link ( $ target , $ caption , $ attributes ) ; return $ link ; }
Create a new Link element
45,730
public function deleteLink ( $ target , $ caption = null , $ confirmMessage = 'Are you sure?' , $ attributes = array ( ) ) { if ( is_array ( $ target ) || is_object ( $ target ) ) { $ target = Url :: instance ( ) -> delete ( $ target ) ; } $ attributes = array_merge ( array ( "data-method" => "delete" , "rel" => "nofollow" ) , $ attributes ) ; if ( is_null ( $ confirmMessage ) ) { $ attributes [ 'data-confirm' ] = 'Are you sure?' ; } elseif ( $ confirmMessage !== false ) { $ attributes [ 'data-confirm' ] = $ confirmMessage ; } $ link = new \ HtmlObject \ Link ( $ target , $ caption , $ attributes ) ; return $ link ; }
Create new delete Link element
45,731
public function listingFor ( $ items , \ Closure $ callback , $ attributes = array ( ) , $ element = 'ul' , $ childElement = 'li' ) { $ list = \ HtmlObject \ Element :: $ element ( '' , $ attributes ) ; $ closureMethod = Reflection :: getClosureMethod ( $ callback ) ; $ closureArgs = Reflection :: getClosureParams ( $ closureMethod ) ; $ index = 0 ; foreach ( $ items as $ item ) { $ li = Reflection :: invokeClosure ( $ callback , array ( $ index , $ item ) , array ( $ item ) ) ; if ( is_string ( $ li ) ) { $ realLi = \ HtmlObject \ Element :: $ childElement ( $ li ) ; $ list -> addChild ( $ realLi ) ; } elseif ( is_subclass_of ( $ li , "\\HtmlObject\\Traits\\Tag" ) ) { if ( $ li -> getTag ( ) !== $ childElement ) { $ realLi = \ HtmlObject \ Element :: $ childElement ( $ li ) ; $ list -> addChild ( $ realLi ) ; } else { $ list -> addChild ( $ li ) ; } } else { throw new \ Exception ( "The ulFor callback needs to return a HTMLObject\\Element, or a string containing HTML." , 1 ) ; } $ index ++ ; } return $ list ; }
Create a listing for the given array of items using a callback for each item
45,732
public function listing ( $ contents = array ( ) , $ attributes = array ( ) , $ element = 'ul' , $ childElement = 'li' ) { $ list = \ HtmlObject \ Element :: $ element ( '' , $ attributes ) ; if ( ! is_null ( $ contents ) && ! is_array ( $ contents ) ) { $ contents = array ( $ contents ) ; } foreach ( $ contents as $ li ) { if ( is_string ( $ li ) ) { $ realLi = \ HtmlObject \ Element :: $ childElement ( $ li ) ; $ list -> addChild ( $ realLi ) ; } elseif ( is_subclass_of ( $ li , "\\HtmlObject\\Traits\\Tag" ) ) { if ( $ li -> getTag ( ) !== $ childElement ) { $ realLi = \ HtmlObject \ Element :: $ childElement ( $ li ) ; $ list -> addChild ( $ realLi ) ; } else { $ list -> addChild ( $ li ) ; } } else { throw new \ Exception ( "Invalid contents for listing. " , 1 ) ; } } return $ list ; }
Create a new listing
45,733
public function li ( $ contents = '' , $ attributes = array ( ) ) { $ li = \ HtmlObject \ Element :: li ( $ contents , $ attributes ) ; return $ li ; }
Create a new list item
45,734
public function start ( $ name = null , $ id = null ) { if ( ! session_id ( ) ) { if ( $ name ) { session_name ( $ name ) ; } if ( $ id ) { session_id ( $ this -> id ) ; } session_start ( ) ; return true ; } return false ; }
Starts the PHP session if not yet started .
45,735
public function destroy ( ) { $ _SESSION = [ ] ; if ( $ this -> cookieJar ) { $ this -> cookieJar -> remove ( $ this -> name ( ) ) ; } else { $ params = session_get_cookie_params ( ) ; setcookie ( $ this -> name ( ) , '' , time ( ) - 42000 , $ params [ "path" ] , $ params [ "domain" ] , $ params [ "secure" ] , $ params [ "httponly" ] ) ; } session_destroy ( ) ; }
Destroys the PHP session .
45,736
public function getHtmlId ( ) { $ form = $ this -> getParentOfType ( '\\Zepi\\Web\\UserInterface\\Form\\Form' ) ; if ( ! $ form ) { return $ this -> key ; } return $ form -> getHtmlId ( ) . '-' . $ this -> key ; }
Returns the html id of this group
45,737
public function getFormFactory ( ) { if ( $ this -> formFactory ) { return $ this -> formFactory ; } $ this -> formFactory = new Factory ( ) ; return $ this -> formFactory ; }
Retrieve form factory
45,738
public function createForm ( $ entity ) { $ formSpec = ArrayUtils :: iteratorToArray ( $ this -> getFormSpecification ( $ entity ) ) ; if ( ! isset ( $ formSpec [ 'options' ] [ 'merge_input_filter' ] ) ) { $ formSpec [ 'options' ] [ 'merge_input_filter' ] = true ; } return $ this -> getFormFactory ( ) -> createForm ( $ formSpec ) ; }
Create a form from an object .
45,739
protected function configureElement ( $ annotations , $ reflection , $ formSpec , $ filterSpec ) { if ( $ this -> checkForExclude ( $ annotations ) ) { return ; } $ events = $ this -> getEventManager ( ) ; $ name = $ this -> discoverName ( $ annotations , $ reflection ) ; $ elementSpec = new ArrayObject ( [ 'flags' => [ ] , 'spec' => [ 'name' => $ name ] , ] ) ; $ inputSpec = new ArrayObject ( [ 'name' => $ name , ] ) ; $ event = new Event ( ) ; $ event -> setParams ( [ 'name' => $ name , 'elementSpec' => $ elementSpec , 'inputSpec' => $ inputSpec , 'formSpec' => $ formSpec , 'filterSpec' => $ filterSpec , ] ) ; foreach ( $ annotations as $ annotation ) { $ event -> setParam ( 'annotation' , $ annotation ) ; $ events -> trigger ( __FUNCTION__ , $ this , $ event ) ; } if ( $ event -> getParam ( 'inputSpec' ) -> count ( ) > 1 || $ annotations -> hasAnnotation ( Input :: class ) ) { if ( $ name === 'type' || $ name === 'filters' || $ name === 'validators' ) { $ filterSpec [ ] = $ event -> getParam ( 'inputSpec' ) ; } else { $ filterSpec [ $ name ] = $ event -> getParam ( 'inputSpec' ) ; } } $ elementSpec = $ event -> getParam ( 'elementSpec' ) ; $ type = isset ( $ elementSpec [ 'spec' ] [ 'type' ] ) ? $ elementSpec [ 'spec' ] [ 'type' ] : Element :: class ; if ( ! $ this -> preserveDefinedOrder ( ) && is_subclass_of ( $ type , FieldsetInterface :: class ) ) { if ( ! isset ( $ formSpec [ 'fieldsets' ] ) ) { $ formSpec [ 'fieldsets' ] = [ ] ; } if ( isset ( $ formSpec [ 'fieldsets' ] [ $ name ] ) ) { $ formSpec [ 'fieldsets' ] [ ] = $ elementSpec ; } else { $ formSpec [ 'fieldsets' ] [ $ name ] = $ elementSpec ; } } else { if ( ! isset ( $ formSpec [ 'elements' ] ) ) { $ formSpec [ 'elements' ] = [ ] ; } if ( isset ( $ formSpec [ 'elements' ] [ $ name ] ) ) { $ formSpec [ 'elements' ] [ ] = $ elementSpec ; } else { $ formSpec [ 'elements' ] [ $ name ] = $ elementSpec ; } } }
Configure an element from annotations
45,740
public function compile ( string $ fromFile , string $ toFile = '' ) { $ fromFile = $ this -> getFilePath ( $ fromFile ) ; $ result = $ this -> execute ( new FileBuffer ( $ this , $ fromFile ) ) ; if ( $ toFile ) { return file_put_contents ( $ toFile , $ result ) ; } else { return $ result ; } }
Compiling a HTSL file into a HTML or PHP file .
45,741
public function setBasePath ( string $ basePath ) : self { $ this -> basePath = '/' === substr ( $ basePath , - 1 ) ? substr ( $ basePath , 0 , - 1 ) : $ basePath ; return $ this ; }
Setting the base path of the HTSL project to parse .
45,742
public function getConfig ( string ... $ keys ) { $ result = $ this -> config ; foreach ( $ keys as $ key ) { if ( ! isset ( $ result [ $ key ] ) ) { return null ; } $ result = $ result [ $ key ] ; } return $ result ; }
Getting the config of Htsl .
45,743
public function getFilePath ( string $ filePath , string $ path = null ) : string { if ( ! isset ( $ this -> basePath ) ) { throw new \ Exception ( 'BasePath musbe set.' ) ; } if ( ! strlen ( $ filePath ) ) { throw new \ Exception ( 'FilePath cannot be empty.' ) ; } if ( '/' === $ filePath { 0 } ) { if ( is_null ( $ path ) ) { return $ filePath ; } else { return $ this -> basePath . $ filePath ; } } else { if ( ! strlen ( $ path ) ) { return $ this -> basePath . '/' . $ filePath ; } elseif ( '/' === substr ( $ path , - 1 ) ) { return $ path . $ filePath ; } else { return $ path . '/' . $ filePath ; } } }
Getting the real file path of the HTSL file by relative path .
45,744
public function getFileContent ( string $ filePath ) : string { return isset ( $ this -> fileGetter ) ? $ this -> fileGetter ( $ filePath ) : file_get_contents ( $ filePath ) ; }
Getting the content of file .
45,745
public static function getInputFor ( \ stdClass $ fieldData ) { $ formData = explode ( ':' , $ fieldData -> type -> ui ) ; $ type = $ formData [ 0 ] ; $ options = isset ( $ formData [ 1 ] ) ? $ formData [ 1 ] : '[]' ; if ( $ type == 'text' || $ type == 'number' || $ type == 'textarea' || $ type == 'date' ) { return '{!! Form::' . $ type . '(\'' . $ fieldData -> name . '\', (isset($model)) ? $model->' . $ fieldData -> name . ' : null, ' . $ options . ') !!}' ; } elseif ( $ type == 'select' ) { $ list = isset ( $ formData [ 1 ] ) ? $ formData [ 1 ] : '[]' ; $ options = isset ( $ formData [ 2 ] ) ? $ formData [ 2 ] : '[]' ; return '{!! Form::select(\'' . $ fieldData -> name . '\', ' . $ list . ', (isset($model)) ? $model->' . $ fieldData -> name . ' : null, ' . $ options . ') !!}' ; } elseif ( $ type == 'selectRange' ) { $ begin = isset ( $ formData [ 1 ] ) ? $ formData [ 1 ] : '0' ; $ end = isset ( $ formData [ 2 ] ) ? $ formData [ 2 ] : '0' ; $ options = isset ( $ formData [ 3 ] ) ? $ formData [ 3 ] : '[]' ; return '{!! Form::selectRange(\'' . $ fieldData -> name . '\', ' . $ begin . ', ' . $ end . ', (isset($model)) ? $model->' . $ fieldData -> name . ' : null, ' . $ options . ') !!}' ; } elseif ( $ type == 'checkbox' ) { $ options = isset ( $ formData [ 1 ] ) ? $ formData [ 1 ] : 'false' ; return '{!! Form::checkbox(\'' . $ fieldData -> name . '\', 1, (isset($model) && $model->' . $ fieldData -> name . ' == 1) ? true : false, ' . $ options . ') !!}' ; } elseif ( $ type == 'radio' ) { array_shift ( $ formData ) ; $ radioGroup = '' ; $ radioId = 0 ; foreach ( $ formData as $ value ) { $ radioGroup .= '{!! Form::radio(\'' . $ fieldData -> name . '\', \'' . $ value . '\', (isset($model) && $model->' . $ fieldData -> name . ' == \'' . $ value . '\') ? true : false, [\'id\' => ' . $ radioId . ']) !!}' ; $ radioId ++ ; if ( end ( $ formData ) != $ value ) $ radioGroup .= PHP_EOL . "\t" ; } return $ radioGroup ; } else { throw new \ Exception ( 'Input type not implemented' ) ; } }
Get the input for the field .
45,746
protected function processMap ( $ arr , $ prefix = '' ) { foreach ( $ arr as $ uri => $ options ) { $ uri = $ prefix . $ this -> preProcessURI ( $ uri ) ; foreach ( $ options as $ method => $ target ) { if ( ! is_array ( $ target ) ) continue ; if ( array_key_exists ( 'name' , $ target ) ) { $ this -> map ( $ method , $ uri , $ target , $ target [ 'name' ] ) ; } else { $ this -> map ( $ method , $ uri , $ target ) ; } } } }
For each array item pre process and add to global mapping
45,747
public function preProcessURI ( $ uri ) { $ s = preg_replace ( "/\{([\w]+)\}/" , "[*:$1]" , $ uri ) ; if ( ! empty ( $ s ) ) { $ uri = $ s ; } return $ uri ; }
Replace the macros by regular expressions to extract arguments from URL
45,748
public function evaluate ( $ target ) { switch ( Utils :: get ( 'type' , $ target ) ) { case 'class' : $ return = $ this -> processClass ( Utils :: get ( 'target' , $ target ) , Utils :: get ( 'match' , $ target ) ) ; break ; case 'controller' : $ return = $ this -> processController ( Utils :: get ( 'target' , $ target ) , Utils :: get ( 'match' , $ target ) ) ; break ; case 'view' : $ return = $ this -> processView ( Utils :: get ( 'target' , $ target ) , Utils :: get ( 'match' , $ target ) ) ; break ; case 'eval' : $ return = eval ( $ target [ 'target' ] [ 'eval' ] ) ; break ; default : throw new \ Exception ( "Undefined target" , 404 ) ; } return $ return ; }
Determine which type of target is and execute it .
45,749
public function resolve ( ) { $ return = false ; $ match = $ this -> match ( ) ; if ( ! $ match ) { $ target = $ this -> getDefaultRoute ( ) ; if ( $ target ) { $ match = [ 'target' => $ target ] ; } } if ( substr ( Utils :: get ( 'name' , $ match , '' ) , 0 , 7 ) == 'plugin:' ) { Application :: getInstance ( ) -> preparePlugin ( $ match [ 'name' ] ) ; } if ( is_array ( $ match ) && array_key_exists ( 'target' , $ match ) ) { $ target = $ match [ 'target' ] ; $ return = [ 'target' => $ target , 'match' => $ match , 'application' => $ this -> getApplicationName ( ) ] ; if ( array_key_exists ( 'class' , $ target ) ) { $ return [ 'type' ] = 'class' ; } elseif ( array_key_exists ( 'controller' , $ target ) ) { $ return [ 'type' ] = 'controller' ; } elseif ( array_key_exists ( 'view' , $ target ) ) { $ return [ 'type' ] = 'view' ; } elseif ( array_key_exists ( 'eval' , $ target ) ) { $ return [ 'type' ] = 'eval' ; } else { $ return = [ 'success' => false , 'msg' => "Target undefined" , 'code' => 404 , 'info' => $ match ] ; } } else { $ return = [ 'success' => false , 'msg' => "Target not found" , 'code' => 404 , 'info' => $ match ] ; } return $ return ; }
Perform the match among the URI and the routes available
45,750
public function assets ( Response $ response , $ asset ) { $ filesystem = new Filesystem ( new Adapter ( FS2ADMIN ) ) ; $ expires = 8640000 ; try { $ timestamp_string = gmdate ( 'D, d M Y H:i:s ' , $ filesystem -> getTimestamp ( $ asset ) ) . 'GMT' ; $ etag = md5 ( $ filesystem -> read ( $ asset ) ) ; $ mime_type = $ filesystem -> getMimetype ( $ asset ) ; if ( 0 !== strpos ( $ mime_type , 'image' ) ) { $ mime_type = 'text/css' ; } $ if_modified_since = isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ? $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] : false ; $ if_none_match = isset ( $ _SERVER [ 'HTTP_IF_NONE_MATCH' ] ) ? $ _SERVER [ 'HTTP_IF_NONE_MATCH' ] : false ; if ( ( ( $ if_none_match && $ if_none_match == "\"{$etag}\"" ) || ( ! $ if_none_match ) ) && ( $ if_modified_since && $ if_modified_since == $ timestamp_string ) ) { return $ response -> withStatus ( '304' ) ; } else { $ response = $ response -> withHeader ( 'Last-Modified' , $ timestamp_string ) -> withHeader ( 'ETag' , "\"{$etag}\"" ) ; } $ response -> getBody ( ) -> write ( $ filesystem -> read ( $ asset ) ) ; return $ response -> withHeader ( 'Expires' , gmdate ( 'D, d M Y H:i:s ' , time ( ) + $ expires ) . 'GMT' ) -> withHeader ( 'Content-Type' , $ mime_type ) -> withHeader ( 'Pragma' , 'cache' ) -> withHeader ( 'Cache-Control' , 'cache' ) ; } catch ( FileNotFoundException $ e ) { throw $ e ; } }
Return admin assets
45,751
public function index ( ) { try { $ jobs = FailedJob :: orderBy ( 'id' , 'DESC' ) -> paginate ( ) ; } catch ( QueryException $ e ) { return $ this -> setup ( ) ; } return view ( 'laravie/quemon::index' , compact ( 'jobs' ) ) ; }
List of failed jobs .
45,752
public function add ( $ value ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } $ this -> _Arr = \ array_merge ( $ this -> _Arr , \ func_get_args ( ) ) ; return $ this ; }
Adds a value to the list multiple can be given
45,753
public function average ( ) { Number :: setScale ( static :: NUMERIC_FUNCTIONS_SCALE ) ; return Number :: divide ( $ this -> sum ( ) , \ strval ( $ this -> count ( ) ) ) ; }
Computes the average value for a list of numbers
45,754
public function chunk ( $ size ) { $ outer = new static ( ) ; $ chunks = \ array_chunk ( $ this -> _Arr , $ size ) ; foreach ( $ chunks as $ chunk ) { $ outer -> pushBack ( new static ( $ chunk ) ) ; } return $ outer ; }
Divides this list into a list of smaller - chunked lists
45,755
public function concat ( ICollection $ coll ) { $ arr = array ( ) ; $ coll -> copyTo ( $ arr ) ; return new static ( \ array_merge ( $ this -> _Arr , \ array_values ( $ arr ) ) ) ; }
Concatenates this list with an ICollection and returns a new list
45,756
public function copy ( $ deep = true ) { $ arr = array ( ) ; foreach ( $ this -> _Arr as $ key => $ item ) { $ arr [ $ key ] = $ deep ? Functions \ Object :: copy ( $ item ) : $ item ; } return new static ( $ arr ) ; }
Creates a copy of this list . By default a deep - copy is performed .
45,757
public function copyTo ( array & $ arr , $ index = 0 ) { if ( ! $ this -> offsetExists ( $ index ) ) { throw new \ OutOfRangeException ( '$index is invalid' ) ; } $ arr = \ array_slice ( $ this -> _Arr , $ index ) ; return $ this ; }
Copies this list to a given array by reference
45,758
public function intersect ( ICollection $ coll ) { $ arr = array ( ) ; $ coll -> copyTo ( $ arr ) ; $ ret = array ( ) ; foreach ( $ this -> _Arr as $ outerItem ) { foreach ( $ arr as $ innerItem ) { if ( $ innerItem === $ outerItem ) { $ ret [ ] = $ outerItem ; break ; } } } return new static ( $ ret ) ; }
Returns a new list with each element existing in this list and a given ICollection
45,759
public function insert ( $ index , $ value ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } if ( ! $ this -> offsetExists ( $ index ) ) { throw new \ OutOfRangeException ( '$index is invalid' ) ; } \ array_splice ( $ this -> _Arr , $ index , 0 , array ( $ value ) ) ; return $ this ; }
Inserts a value into the list at a given index
45,760
public function insertRange ( $ index , ICollection $ coll ) { if ( $ this -> _ReadOnly ) { throw new \ RuntimeException ( \ get_called_class ( ) . ' is read only' ) ; } if ( ! $ this -> offsetExists ( $ index ) ) { throw new \ OutOfRangeException ( '$index is invalid' ) ; } $ arr = array ( ) ; $ coll -> copyTo ( $ arr ) ; \ array_splice ( $ this -> _Arr , $ index , 0 , $ arr ) ; return $ this ; }
Inserts a collection of items into the list at a given index
45,761
public function lastIndexOf ( $ value ) { $ i = $ this -> count ( ) - 1 ; while ( $ i >= 0 && $ this -> _Arr [ $ i ] !== $ value ) { -- $ i ; } return $ i ; }
Returns the index of the last matching value
45,762
public function max ( ) { if ( $ this -> isEmpty ( ) ) { throw new \ UnderflowException ( \ get_called_class ( ) . ' is empty' ) ; } $ max = $ this -> front ( ) ; for ( $ i = 1 , $ l = $ this -> count ( ) ; $ i < $ l ; ++ $ i ) { if ( Number :: greaterThan ( $ this -> _Arr [ $ i ] , $ max ) ) { $ max = $ this -> _Arr [ $ i ] ; } } return $ max ; }
Returns the maximum value of this list . Result is undefined for non numeric lists .
45,763
public function min ( ) { if ( $ this -> isEmpty ( ) ) { throw new \ UnderflowException ( \ get_called_class ( ) . ' is empty' ) ; } $ min = $ this -> front ( ) ; for ( $ i = 1 , $ l = $ this -> count ( ) ; $ i < $ l ; ++ $ i ) { if ( Number :: lessThan ( $ this -> _Arr [ $ i ] , $ min ) ) { $ min = $ this -> _Arr [ $ i ] ; } } return $ min ; }
Returns the minimum value of this list . Result is undefined for non numeric lists .
45,764
public function popBack ( ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } if ( $ this -> isEmpty ( ) ) { throw new \ UnderflowException ( \ get_called_class ( ) . ' is empty' ) ; } return \ array_pop ( $ this -> _Arr ) ; }
Removes and returns the last element of the list
45,765
public function popFront ( ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } if ( $ this -> isEmpty ( ) ) { throw new \ UnderflowException ( \ get_called_class ( ) . ' is empty' ) ; } return \ array_shift ( $ this -> _Arr ) ; }
Removes and returns the first element of the list
45,766
public function product ( ) { Number :: setScale ( static :: NUMERIC_FUNCTIONS_SCALE ) ; $ total = \ strval ( $ this -> front ( ) ) ; for ( $ i = 1 , $ l = $ this -> count ( ) ; $ i < $ l ; ++ $ i ) { $ total = Number :: multiply ( $ total , \ strval ( $ this -> _Arr [ $ i ] ) ) ; } return $ total ; }
Computes the product of a list of numbers
45,767
public function pushBack ( ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } $ this -> _Arr = \ array_merge ( $ this -> _Arr , \ func_get_args ( ) ) ; return $ this ; }
Adds items to the end of this list . Multiple arguments can be given .
45,768
public function pushFront ( ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } $ this -> _Arr = \ array_merge ( \ func_get_args ( ) , $ this -> _Arr ) ; return $ this ; }
Adds items to the beginning of this list . Multiple arguments can be given .
45,769
public function & random ( ) { if ( $ this -> isEmpty ( ) ) { throw new \ UnderflowException ( \ get_called_class ( ) . ' is empty' ) ; } return $ this -> _Arr [ \ array_rand ( $ this -> _Arr , 1 ) ] ; }
Returns a reference to a random item from the list
45,770
public function readOnly ( $ bool = true ) { $ list = $ this -> copy ( false ) ; $ list -> setReadOnly ( ) ; return $ list ; }
Creates a shallow copy of this list and sets it to read only
45,771
public function remove ( $ value ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } if ( ( $ key = \ array_search ( $ value , $ this -> _Arr ) ) !== false ) { \ array_splice ( $ this -> _Arr , $ key , 1 ) ; } return $ this ; }
Removes the first matching value from the list
45,772
public function removeAt ( $ index ) { if ( $ this -> _ReadOnly ) { throw new \ RuntimeException ( \ get_called_class ( ) . ' is read only' ) ; } if ( ! $ this -> offsetExists ( $ index ) ) { throw new \ OutOfRangeException ( '$index is invalid' ) ; } \ array_splice ( $ this -> _Arr , $ index , 1 ) ; return $ this ; }
Removes a value at the given index
45,773
public function resize ( $ size , $ value = null ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } if ( ! \ is_int ( $ size ) ) { throw new \ InvalidArgumentException ( '$size is not an int' ) ; } if ( $ size < 0 ) { throw new \ OutOfBoundsException ( '$size cannot be less than 0' ) ; } $ len = $ this -> count ( ) ; if ( $ size > $ len ) { $ this -> _Arr = \ array_pad ( $ this -> _Arr , $ size , $ value ) ; } else if ( $ size < $ len ) { $ this -> _Arr = \ array_slice ( $ this -> _Arr , 0 , $ size , false ) ; } return $ this ; }
Resizes this list to a given size . Expanding the list will pad it with a value . Contracting the list cuts off extraneous values .
45,774
public function reverse ( ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } $ this -> _Arr = \ array_reverse ( $ this -> _Arr ) ; return $ this ; }
Reverses this list
45,775
public function sentinelSearch ( $ value ) { $ l = $ this -> count ( ) ; $ arr = $ this -> _Arr ; $ arr [ $ l ] = $ value ; $ i = 0 ; while ( $ arr [ $ i ] !== $ value ) { ++ $ i ; } return $ i !== $ l ? $ i : static :: NO_INDEX ; }
Performs a sentinel search for a value
45,776
public function slice ( $ index , $ count = null ) { if ( ! $ this -> offsetExists ( $ index ) ) { throw new \ OutOfRangeException ( '$index is invalid' ) ; } $ arr = \ array_slice ( $ this -> _Arr , $ index , $ count ) ; return new static ( $ arr ) ; }
Creates a new list from a subset of this list
45,777
public function sort ( \ Closure $ compare = null ) { if ( $ this -> _ReadOnly ) { throw new ReadOnlyException ( \ get_called_class ( ) . ' is read only' ) ; } if ( \ is_callable ( $ compare ) ) { \ usort ( $ this -> _Arr , $ compare ) ; } else { \ sort ( $ this -> _Arr ) ; } return $ this ; }
Sorts this list optionally by a user defined compare function
45,778
public function sum ( ) { Number :: setScale ( static :: NUMERIC_FUNCTIONS_SCALE ) ; $ total = '0' ; foreach ( $ this -> _Arr as $ item ) { $ total = Number :: add ( $ total , \ strval ( $ item ) ) ; } return $ total ; }
Computes the sum of all numbers in this list
45,779
public function stdDev ( ) { Number :: setScale ( static :: NUMERIC_FUNCTIONS_SCALE ) ; $ mean = $ this -> average ( ) ; $ squares = new static ( ) ; foreach ( $ this -> _Arr as $ num ) { $ squares -> add ( Number :: pow ( Number :: sub ( \ strval ( $ num ) , $ mean ) , '2' ) ) ; } return Number :: sqrt ( $ squares -> average ( ) ) ; }
Computes the population standard deviation for the numbers in this list
45,780
public function unique ( \ Closure $ compare = null ) { if ( \ is_callable ( $ compare ) ) { $ arr = new static ( ) ; $ this -> each ( function ( $ outerItem ) use ( & $ arr , $ compare ) { if ( ! $ arr -> some ( function ( $ cmpItem ) use ( $ outerItem , $ compare ) { return $ compare ( $ outerItem , $ cmpItem ) ; } ) ) { $ arr -> _Arr [ ] = $ outerItem ; } } ) ; return $ arr ; } else { return new static ( \ array_values ( \ array_unique ( $ this -> _Arr , \ SORT_REGULAR ) ) ) ; } }
Eliminates duplicate values from this list optionally according to a user defined compare function
45,781
public function call ( MethodArgumentDocument $ methodArgument ) { $ serviceName = $ methodArgument -> getMethod ( ) -> getService ( ) -> getServiceName ( ) ; $ service = $ this -> container -> get ( $ serviceName ) ; if ( null === $ service ) { throw new UndefinedServiceException ( sprintf ( '"%s" is not a service' , $ serviceName ) ) ; } $ methodName = $ methodArgument -> getMethod ( ) -> getName ( ) ; try { $ r = new \ ReflectionMethod ( $ service , $ methodName ) ; } catch ( \ ReflectionException $ e ) { throw new BadMethodCallException ( sprintf ( '"%s" is not a method in %s' , $ methodName , $ serviceName ) ) ; } $ methodArguments = $ methodArgument -> getArguments ( ) ; $ numberOfArgs = $ methodArguments -> count ( ) ; $ minArgs = $ r -> getNumberOfRequiredParameters ( ) ; $ maxArgs = $ r -> getNumberOfParameters ( ) ; if ( $ numberOfArgs < $ minArgs || $ numberOfArgs > $ maxArgs ) { $ range = $ minArgs === $ maxArgs ? $ minArgs : "$minArgs-$maxArgs" ; throw new WrongNumberOfArgumentsException ( sprintf ( 'Method "%s" in %s expects %s arguments, got %d' , $ methodName , $ serviceName , $ range , $ numberOfArgs ) ) ; } return $ service -> $ methodName ( ... $ this -> buildArgumentArray ( $ r -> getParameters ( ) , $ methodArguments ) ) ; }
Executes the passed in method via the associated service that s retrieved from the container . This gets called recursively to supply all the arguments for each given method .
45,782
public function checkProfileEditPermission ( $ user_id ) { $ current_user_id = App :: make ( 'sentry' ) -> getUser ( ) -> id ; if ( $ user_id == $ current_user_id ) { return true ; } $ edit_perm = Config :: get ( 'authentication::permissions.edit_profile' ) ; if ( $ this -> hasPermission ( $ edit_perm ) ) { return true ; } return false ; }
Check if the current user has permission to edit the profile
45,783
public function getNotificationRegistrationUsersEmail ( ) { $ group_name = Config :: get ( 'authentication::permissions.profile_notification_group' ) ; $ user_r = App :: make ( 'user_repository' ) ; $ users = $ user_r -> findFromGroupName ( $ group_name ) -> lists ( 'email' ) ; return $ users ; }
Obtain the user that needs to be notificated on registration
45,784
public function addTemplatingEngineClass ( array & $ globalConfig , string $ templateEngineClass ) { $ globalConfig [ $ this -> getModuleKey ( ) ] [ self :: CONFIG_ENGINES ] [ ] = $ templateEngineClass ; }
Adds a class as a possible template engine . This must be done before the configureDependencyInjection function is called .
45,785
public function configureDependencyInjection ( DependencyInjectionContainer $ dic , array $ moduleConfig , array $ globalConfig ) { $ engines = [ ] ; if ( empty ( $ moduleConfig [ self :: CONFIG_ENGINES ] ) ) { throw new ConfigurationException ( 'The templating module itself was loaded, but there is no module ' . ' for the actual template engine present. Did you forget to load your templating module?' ) ; } foreach ( $ moduleConfig [ self :: CONFIG_ENGINES ] as $ engineClass ) { $ engines [ ] = $ dic -> make ( $ engineClass ) ; } if ( isset ( $ moduleConfig [ self :: CONFIG_FILTERS ] ) ) { foreach ( $ moduleConfig [ self :: CONFIG_FILTERS ] as $ filterClass ) { $ filterInstance = $ dic -> make ( $ filterClass ) ; if ( $ filterInstance instanceof TemplateFilter ) { foreach ( $ engines as $ engine ) { $ engine -> registerFilter ( $ filterInstance ) ; } } else { throw new ConfigurationException ( $ filterClass . ' does not implement ' . TemplateFilter :: class ) ; } } } if ( isset ( $ moduleConfig [ self :: CONFIG_FUNCTIONS ] ) ) { foreach ( $ moduleConfig [ self :: CONFIG_FUNCTIONS ] as $ functionClass ) { $ functionInstance = $ dic -> make ( $ functionClass ) ; if ( $ functionInstance instanceof TemplateFunction ) { foreach ( $ engines as $ engine ) { $ engine -> registerFunction ( $ functionInstance ) ; } } else { throw new ConfigurationException ( $ functionClass . ' does not implement ' . TemplateFunction :: class ) ; } } } $ dic -> setClassParameters ( TemplateRenderingChain :: class , [ 'templateEngines' => $ engines ] ) ; }
Configures the TemplateRenderingChain with the previously registered templating engines .
45,786
private function serializeObject ( $ object , string $ className = null ) { if ( is_null ( $ className ) ) { $ index = array_search ( $ object , $ this -> references , true ) ; if ( $ index !== false ) { $ this -> referencesUsed [ ] = $ index ; return [ '@ref' => $ index ] ; } $ this -> references [ ] = $ object ; } $ data = [ '@type' => get_class ( $ object ) ] ; $ reflectionClass = new \ ReflectionClass ( $ className ? $ className : $ object ) ; $ parent = $ reflectionClass -> getParentClass ( ) ; if ( $ parent ) { $ parentData = $ this -> serializeObject ( $ object , $ parent -> getName ( ) ) ; if ( count ( $ parentData ) > 0 ) { $ data = array_merge ( $ data , $ parentData ) ; } } foreach ( $ reflectionClass -> getProperties ( ) as $ property ) { $ property -> setAccessible ( true ) ; $ value = $ property -> getValue ( $ object ) ; $ name = $ property -> getName ( ) ; if ( isset ( $ data [ $ name ] ) ) { continue ; } $ defaults = $ reflectionClass -> getDefaultProperties ( ) ; if ( array_key_exists ( $ name , $ defaults ) && $ defaults [ $ name ] === $ value ) { continue ; } $ this -> serializeValue ( $ name , $ value , $ data ) ; } if ( ! $ className ) { foreach ( get_object_vars ( $ object ) as $ key => $ value ) { if ( ! isset ( $ data [ $ key ] ) ) { $ this -> serializeValue ( $ key , $ value , $ data ) ; } } } return $ data ; }
Recursive serialize .
45,787
private function unserializeObject ( $ object , & $ data , string $ className = null ) : array { $ reflectionClass = new \ ReflectionClass ( $ className ? $ className : $ object ) ; unset ( $ data [ '@type' ] ) ; $ parent = $ reflectionClass -> getParentClass ( ) ; if ( $ parent ) { $ this -> unserializeObject ( $ object , $ data , $ parent -> getName ( ) ) ; } foreach ( $ reflectionClass -> getProperties ( ) as $ property ) { $ name = $ property -> getName ( ) ; if ( array_key_exists ( $ name , $ data ) ) { $ currentValue = $ data [ $ name ] ; if ( isset ( $ data [ $ name ] [ '@ref' ] ) ) { $ currentValue = $ this -> references [ $ data [ $ name ] [ '@ref' ] ] ; } elseif ( isset ( $ data [ $ name ] [ '@type' ] ) ) { $ reflection = new \ ReflectionClass ( $ data [ $ name ] [ '@type' ] ) ; $ parent = $ reflection ; $ internal = false ; while ( $ parent !== false ) { $ internal = $ parent -> isInternal ( ) ? true : $ internal ; $ parent = $ parent -> getParentClass ( ) ; } if ( $ internal ) { $ currentData = $ data [ $ name ] ; $ currentType = $ data [ $ name ] [ '@type' ] ; unset ( $ currentData [ '@type' ] ) ; $ serialize = preg_replace ( '`^a:`' , 'O:' . strlen ( $ currentType ) . ':"' . $ currentType . '":' , serialize ( $ currentData ) ) ; $ currentValue = unserialize ( $ serialize ) ; } else { $ currentValue = $ reflection -> newInstanceWithoutConstructor ( ) ; $ this -> unserializeObject ( $ currentValue , $ data [ $ name ] ) ; } } elseif ( is_array ( $ currentValue ) ) { $ currentValue = [ ] ; foreach ( $ data [ $ name ] as $ key => $ value ) { if ( isset ( $ value [ '@type' ] ) ) { $ reflection = new \ ReflectionClass ( $ value [ '@type' ] ) ; $ currentValue [ $ key ] = $ reflection -> newInstanceWithoutConstructor ( ) ; $ this -> unserializeObject ( $ currentValue [ $ key ] , $ value ) ; } else { $ currentValue [ $ key ] = $ value ; } } } $ property -> setAccessible ( true ) ; $ property -> setValue ( $ object , $ currentValue ) ; unset ( $ data [ $ name ] ) ; } } return $ data ; }
Recursive unserialize to get parent class property .
45,788
protected function _q45 ( EarthIT_Schema_ResourceClass $ rc , array $ items ) { $ restObjects = array ( ) ; foreach ( $ items as $ item ) { $ restObjects [ ] = $ this -> internalObjectToJao ( $ rc , $ item ) ; } return $ restObjects ; }
Convert the given rows from internal to REST format according to the specified resource class .
45,789
public function newSimpleOutput ( ) { $ config = $ this -> config -> getCurrentResourceConfiguration ( ) ; return new SimpleOutput ( $ this -> newSerializer ( $ config ) , $ this -> newResource ( $ config ) ) ; }
Creates a SimpleOutput instance to be used with native PHP .
45,790
public function newSlimOutput ( Request $ request , Response $ response ) { $ config = $ this -> config -> getCurrentResourceConfiguration ( ) ; return new SlimOutput ( $ request , $ response , $ this -> newSerializer ( $ config ) , $ this -> newResource ( $ config ) ) ; }
Creates a SlimOutput instance to be used with the slim PHP framework .
45,791
public function generateSlimRoutes ( Slim $ slim ) { if ( ! $ this -> config -> getCurrentResourceConfiguration ( ) ) { return ; } $ output = $ this -> newSlimOutput ( $ slim -> request , $ slim -> response ) ; $ generator = new SlimRouteGenerator ( $ slim , $ output , $ this -> config ) ; $ generator -> generateRoutes ( ) ; }
Helper for generating all the routes for the configured resources in slim .
45,792
public function resourceFor ( $ resourceName ) { $ resourceConfig = $ this -> config -> resourceConfigurationFor ( $ resourceName ) ; return $ this -> newResource ( $ resourceConfig ) ; }
Finds a ResourceConfiguration for given resource name .
45,793
protected function newRepository ( ResourceConfiguration $ config ) { if ( $ this -> database instanceof EntityManager ) { return $ this -> newDoctrineRepository ( $ this -> database , $ config -> getEntityClass ( ) , $ config -> getParent ( ) ) ; } elseif ( $ this -> database instanceof PDO ) { return $ this -> newPdoRepository ( $ this -> database , $ config -> getResource ( ) , $ config -> getParent ( ) ) ; } throw new \ Exception ( "Couldn't determine database connection type." ) ; }
Determines which repository to use based on the database connection that was passed in .
45,794
protected function newSerializer ( ResourceConfiguration $ config ) { return new JMSSerializer ( SerializerBuilder :: create ( ) -> build ( ) , new SerializationContext , new JMSPropertyExcluder ( $ config -> getExcludedProperties ( ) ) ) ; }
Creates JMSSerializer instance .
45,795
protected function newResource ( ResourceConfiguration $ config ) { return new Resource ( $ this -> newRepository ( $ config ) , $ this -> newValidator ( $ config ) , $ this -> newSecurity ( ) , $ this , $ config ) ; }
Creates a new Resource based off its ResourceConfiguration
45,796
protected function newValidator ( ResourceConfiguration $ config ) { $ class = $ config -> getValidatorClass ( ) ; return $ config -> isUsingYamlValidation ( ) ? new YamlResourceValidator ( $ config -> getYamlValidation ( ) ) : new $ class ( ) ; }
Checks the configuration to decide what validation class to use .
45,797
protected function newSecurity ( ) { $ config = $ this -> config -> getCurrentResourceConfiguration ( ) ; return new Security ( new SimpleAuthenticationBouncer ( $ config ) , new SimpleRoleBouncer ( $ config ) , new ParentBouncer ( $ config ) ) ; }
Creates a Security gateway with all Bouncers
45,798
public function callApi ( Message $ req , $ method , $ uri , $ handler ) { if ( ! is_callable ( $ handler ) ) { throw new GeneralException ( "Can not find response handler." ) ; } $ data = [ 'json' => ( object ) $ req -> to_array ( ) , 'http_errors' => false , ] ; $ response = $ this -> request ( $ method , $ uri , $ data ) ; $ rawContent = $ response -> getBody ( ) -> getContents ( ) ; $ content = json_decode ( $ rawContent , true ) ; if ( ! $ content ) { throw new GeneralException ( "Response is not json data: " . $ rawContent ) ; } $ statusCode = $ response -> getStatusCode ( ) ; switch ( $ statusCode ) { case 200 : if ( isset ( $ content ) ) { return $ handler ( $ content , "" , "" ) ; } else { throw new GeneralException ( "Cannot find response body: " . $ rawContent ) ; } break ; case 400 : if ( isset ( $ content ) ) { return $ handler ( "" , $ content , "" ) ; } throw new GeneralException ( "Cannot find Biz Error body: " . $ rawContent ) ; break ; case 420 : if ( isset ( $ content ) ) { return $ handler ( "" , "" , $ content ) ; } throw new GeneralException ( "Cannot find Common Error body: " . $ rawContent ) ; break ; case 500 : throw new InternalServerErrorException ( "Internal server error: " . $ rawContent ) ; break ; } }
call api handle error return response
45,799
public function diff ( Repository $ otherRepository ) { $ diffRepository = new Memory ( ) ; foreach ( $ this -> unitOfWorkStore as $ unitOfWork ) { if ( ! $ otherRepository -> contains ( $ unitOfWork ) ) { $ diffRepository -> add ( $ unitOfWork ) ; } } $ diffRepository -> sort ( ) ; return $ diffRepository ; }
Calculates the diff to the given repository